js-webflow-api icon indicating copy to clipboard operation
js-webflow-api copied to clipboard

cmsLocaleId is mandatory

Open tobyt42 opened this issue 9 months ago • 6 comments

Hi,

I'm trying to switch to the new API, but getting a validation error when trying to patch an item

statusCode: 400,
  body: {
    message: `Validation Error: ["Value (cmsLocaleId)'s type should be string"]`,
    code: 'validation_error',
    externalReference: null,
    details: []
  }

The code used for patching the item is pretty simple:

      const newItem = {
        ...oldItem,
        isArchived: false,
        isDraft: false,
        fieldData,
      };

      await client.collections.items.updateItemLive(
          collectionID,
          newItem.id,
          newItem
        );

oldItem is retrieved via webflow API and does not contain cmsLocaleId.

According to API docs at https://developers.webflow.com/v2.0.0/data/reference/cms/collection-items/live-items/update-items-live this parameter should be optional. Could you help please?

I have seen this issue with v2.4.2 and on the latest version 3.1.0

I explored setting the cmsLocaleId value to the primary locale, but locales on the site object (https://developers.webflow.com/v2.0.0/data/reference/sites/get) is undefined. I only have API access to this webflow site, so I don't know what settings there are in the UI.

tobyt42 avatar Mar 10 '25 20:03 tobyt42

It seems to accept the request if I set cmsLocaleId to the same value as oldItem.id. Is the id the expected value to set for cmsLocaleId if a site does not use localisation?

tobyt42 avatar Mar 10 '25 21:03 tobyt42

Hey @tobyt42 - no, this should be an optional parameter, and is likely there's an issue with the SDK unexpectedly requiring this parameter for this endpoint 🤔

We'll take a look next chance we get, thank you for raising.

zplata avatar Mar 10 '25 21:03 zplata

Thanks @zplata , is there any harm in setting cmsLocaleId to the id value in the meantime?

tobyt42 avatar Mar 10 '25 21:03 tobyt42

Hey @tobyt42 - sorry for the delay, can you actually see if you're including cmsLocaleId in the payload, but with an undefined value? I'm only able to repro your error if I include it with

{
  "cmsLocaleId": undefined,
  "fieldData": { . . . }
}

It may be that the SDK is trying to be strict, even if you pass in value of undefined there. I might recommend ensuring you omit the cmsLocaleId in this payload if you're not setting an explicit value here.

zplata avatar Mar 14 '25 16:03 zplata

I'm not setting it myself, but I spread the old version of the object (oldItem see code excerpt above) as received from the API via collections.items.listItems()

export async function getAllCollectionItems(
  collection: CollectionListArrayItem,
  api: WebflowClient,
  items: CollectionItem[] = [],
  offset = 0
) {
  const { items: newItems } = await api.collections.items.listItems(
    collection.id,
    {
      offset,
      limit: 100,
    }
  );

  if (newItems) {
    items.push(...newItems);
  }

  if (newItems && newItems.length === 100) {
    return await getAllCollectionItems(collection, api, items, offset + 100);
  }

  return items;
}

It didn't seem like the undefined value was included in the item received from webflow, but let me double check this later and get back to you

tobyt42 avatar Mar 14 '25 17:03 tobyt42

Ok yeah my bad, the object does include cmsLocaleId: undefined, coming from the CollectionItem received from the listItems calls. Deleting the field works around the issue. Thanks @zplata

tobyt42 avatar Mar 14 '25 18:03 tobyt42