Can't publish record successfully

Hi there,
currently, I’m working on publish record through content management API, here’s my example code

async function publishRecord() {
  const res = await client.item.publish('UR_-UEwVSMeHP3e_LbqadA', {
    content_in_locales: [''],
    non_localized_content: true,
  })
}

publishRecord()

And I got a 422 ApiException error:
ApiException: 422 INVALID_FORMAT (details: {“messages”:[“#/data: failed schema #/definitions/item/links/13/schema/properties/data: "id" is not a permitted key.”]})

I checked the official doc Publish a record - Record - Content Management API but there’s no example on there,

Here’s how I test it

  1. create a new record on DatoCMS UI
  2. click publish button on the UI (it works good)
  3. unpublish the record and publish again through Dato Management API
  4. get the error

Did anyone know in which step I may do something wrong? Thank you!

Hi @jeff.f.chen,

Is it possible you’re using the old, now-deprecated datocms-client instead of @datocms/cma-client-node? This is a known problem with that client. From a similar thread: `INVALID_FORMAT` / 'id is not a permitted key' error on `item.publish()` with `datocms-client` (edited title) - #2 by roger

The workaround is to add serializeRequest: false as the third parameter, like this:

async function publishRecord() {
  const res = await client.item.publish('UR_-UEwVSMeHP3e_LbqadA',
 // body
 {
    content_in_locales: [''],
    non_localized_content: true,
  },

  // empty query string
  {},

  // the workaround goes here
  { serializeRequest: false }
)
}

(Or, if time allows, upgrading to the new client as soon as possible: https://www.npmjs.com/package/@datocms/cma-client-node)

Hi Roger,
Yes we’re still using the old datocms-client.
Thanks for the workaround! it works!

1 Like