diff --git a/public/app/api/clients/folder/v1beta1/index.ts b/public/app/api/clients/folder/v1beta1/index.ts index cefd69c4955..bb0e11f218f 100644 --- a/public/app/api/clients/folder/v1beta1/index.ts +++ b/public/app/api/clients/folder/v1beta1/index.ts @@ -24,24 +24,6 @@ export const folderAPIv1beta1 = generatedAPI // We don't want delete to invalidate getFolder tags, as that would lead to unnecessary 404s invalidatesTags: (result, error) => (error ? [] : [{ type: 'Folder', id: 'LIST' }]), }, - updateFolder: { - query: (queryArg) => ({ - url: `/folders/${queryArg.name}`, - method: 'PATCH', - // We need to stringify the body and set the correct header for the call to work with k8s api. - body: JSON.stringify(queryArg.patch), - headers: { - 'Content-Type': 'application/strategic-merge-patch+json', - }, - params: { - pretty: queryArg.pretty, - dryRun: queryArg.dryRun, - fieldManager: queryArg.fieldManager, - fieldValidation: queryArg.fieldValidation, - force: queryArg.force, - }, - }), - }, }, }) .injectEndpoints({ @@ -98,4 +80,4 @@ export const { } = folderAPIv1beta1; // eslint-disable-next-line no-barrel-files/no-barrel-files -export { type Folder, type FolderList, type CreateFolderApiArg, type ReplaceFolderApiArg } from './endpoints.gen'; +export { type CreateFolderApiArg, type Folder, type FolderList, type ReplaceFolderApiArg } from './endpoints.gen'; diff --git a/public/app/api/createBaseQuery.ts b/public/app/api/createBaseQuery.ts index ac282ddc192..51037493e88 100644 --- a/public/app/api/createBaseQuery.ts +++ b/public/app/api/createBaseQuery.ts @@ -15,12 +15,26 @@ interface CreateBaseQueryOptions { export function createBaseQuery({ baseURL }: CreateBaseQueryOptions): BaseQueryFn { async function backendSrvBaseQuery(requestOptions: RequestOptions) { try { + const headers: Record = { + ...requestOptions.headers, + }; + + // Add Content-Type header for PATCH requests to /apis/ endpoints if not already set + if ( + requestOptions.method?.toUpperCase() === 'PATCH' && + baseURL?.startsWith('/apis/') && + !headers['Content-Type'] + ) { + headers['Content-Type'] = 'application/strategic-merge-patch+json'; + } + const { data: responseData, ...meta } = await lastValueFrom( getBackendSrv().fetch({ ...requestOptions, url: baseURL + requestOptions.url, showErrorAlert: requestOptions.showErrorAlert ?? false, data: requestOptions.body, + headers, }) ); return { data: responseData, meta }; diff --git a/public/app/core/utils/fetch.ts b/public/app/core/utils/fetch.ts index e714e944dc9..5be200a2eee 100644 --- a/public/app/core/utils/fetch.ts +++ b/public/app/core/utils/fetch.ts @@ -91,7 +91,9 @@ export const isContentTypeJson = (headers: Headers) => { const contentType = headers.get('content-type'); if ( contentType && - (contentType.toLowerCase() === 'application/json' || contentType.toLowerCase() === 'application/merge-patch+json') + ['application/json', 'application/merge-patch+json', 'application/strategic-merge-patch+json'].includes( + contentType.toLowerCase() + ) ) { return true; }