Add item to collection not working

Hi all,

We’re trying to add/update Webflow items in a collection. We’re able to connect and get details but updating seems to be working only intermittently at best (e.g., worked twice but haven’t able to see why or why not). We’ve confirmed that the key we’re using has the appropriate CMS write permissions.

This is a JavaScript stack the NPM SDK webflow-api webflow-api - npm That SDK uses the js-webflow-api GitHub - webflow/js-webflow-api: Node.js SDK for the Webflow Data API

We’re getting a JsonError: Missing required key "id" error but the library function call createItemLive we’re using doesn’t have an ‘id’ parameter.

createItemLive: js-webflow-api/src/api/resources/collections/resources/items/client/Client.ts at ed20f1448f3010c6d0ad7fd3ab0a6990c02998d1 · webflow/js-webflow-api · GitHub

The WEBFLOW_API_TOKEN is generated from Site Settings > Apps & Integrations > API Access. We confirmed that the token has CMS Write permissions.

Any tips would be much appreciated. Thanks much in advance!

const webflow = new WebflowClient({
  accessToken: process.env.WEBFLOW_API_TOKEN,
})

// This works ok.
const collectionItems = await webflow.collections.items.listItemsLive(process.env.WEBFLOW_COLLECTION_ID)
console.info(`Webflow collection items:`, collectionItems)

// This doesn't work and returns an error of "An error occurred JsonError: Missing required key "id" at /var/task/node_modules/.pnpm/webflow-api@2.3.5/node_modules/webflow-api/core/schemas/builders/schema-utils/getSchemaUtils.js:32:19"
const newListing = {
  isArchived: false,
  isDraft: false,
  fieldData: {
    name: 'Foo Bar',
    slug: 'foo-bar',
  },
}
console.info(`Adding item to Webflow collection`, newListing)
const addedItem = await webflow.collections.items.createItemLive(process.env.WEBFLOW_COLLECTION_ID, newListing)

I don’t use the SDK, but I have a suspicion-

In v1 of the API the createItem call and the ability to make the item Live could happen within the same call.

In the current v2, I believe they’re still separate, you need to createItem, and then take that ID and call a separate API to make it live.

I don’t know what that would translate to in the SDK, but my guess is that either it’s v1 and you’re trying to use it against v2, or it’s outdated in some way. Try to use the v2 API and try to separate those calls.

Hi @memetican,

Thanks much for the speedy reply. As far as I know, the SDK is using v2 based on the docs. Per GitHub - webflow/js-webflow-api: Node.js SDK for the Webflow Data API V2 Migration Guide The SDK was rewritten in V2 and is now programatically generated from our OpenAPI spec. As part of this release there are some breaking changes. so I don’t think we’re using the v1 API.

That said, per your hint, we just tried using createItem instead and it worked! I’m pretty sure we tried createItem before as well but maybe we had something else causing a conflict at that time. shrug

Anyway, it’s working for now and that hint helped. We’ll keep going and if we run into the issue again, we’ll pop back in.

Thanks so much Michael!

1 Like