Using the plain api and updating locales for a given space / environment will not work following until you ignore code warnings and hack arround.
Given a contentful client initialized with
const client = contentful.createClient({
accessToken: Deno.env.get("CONTENTFUL_MANAGEMENT_TOKEN") || "",
host: Deno.env.get("CONTENTFUL_API_HOST") || "",
}, {type: "plain", defaults: {
spaceId: Deno.env.get("CONTENTFUL_SPACE_ID") || "",
environmentId:Deno.env.get("CONTENTFUL_ENV_ID") | ""
}});
and assured that the client works on fetching locales like
const locales = await client.locale.getMany({query: {limit: 100}});
const localeCodeToLocaleMap = new Map(locales.items.map(l => [l.code, l]))
and assuming that there is a locale cs, then the following code will return a error code 500:
const csLocale = localeCodeToLocaleMap.get('cs');
await client.locale.update({localeId: csLocale.sys.id}, {...csLocale, name: "Czech"})
warning Server 500 error occurred. Waiting for 1996 ms before retrying...
warning Server 500 error occurred. Waiting for 2609 ms before retrying...
warning Server 500 error occurred. Waiting for 3406 ms before retrying...
warning Server 500 error occurred. Waiting for 4681 ms before retrying...
warning Server 500 error occurred. Waiting for 6244 ms before retrying...
Stack trace:
ServerError: {
"status": 500,
"statusText": "Internal Server Error",
"message": "",
"details": {},
"request": {
"url": "/spaces/XXXXXXXXX/environments/master/locales/1iJW14UjmAXMOK7izUKHK3",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/vnd.contentful.management.v1+json",
"X-Contentful-User-Agent": "sdk contentful-management-plain.js/11.47.1; platform node.js/v20.11.1; os Linux/v20.11.1;",
"Authorization": "Bearer .............",
"X-Contentful-Version": "3",
"User-Agent": "axios/1.7.9",
"Content-Length": "140",
"Accept-Encoding": "gzip, compress, deflate, br"
},
"method": "put",
"payloadData": "{\"name\":\"Czech\",\"internal_code\":\"cs\",\"code\":\"cs\",\"fallbackCode\":null,\"contentManagementApi\":true,\"contentDeliveryApi\":true,\"optional\":false}"
},
"requestId": "----------------------------------"
}
Reason: The client is sending the field internal_code which will result in the 500 Error.
Workarround with typescript errors as result:
await client.locale.update({localeId: csLocale.sys.id}, {...csLocale, name: "Czech", internal_code: undefined,})
Using the
plainapi and updating locales for a given space / environment will not work following until you ignore code warnings and hack arround.Given a contentful client initialized with
and assured that the client works on fetching locales like
and assuming that there is a locale
cs, then the following code will return a error code 500:Reason: The client is sending the field
internal_codewhich will result in the 500 Error.Workarround with typescript errors as result: