`INVALID_FORMAT` / 'id is not a permitted key' error on `item.publish()` with `datocms-client` (edited title)

Hi DatocMS Community,

We’re encountering an odd error with the JS client datocms-client@3.5.15 when calling publish on a record and isn’t clear how to resolve based on the error message.

The error response to the publish call (which sends a PUT request to https://site-api.datocms.com/items/[Record ID]/publish?recursive=true) is:

{
    "data": [
        {
            "id": "f53cc9",
            "type": "api_error",
            "attributes": {
                "code": "INVALID_FORMAT",
                "details": {
                    "messages": [
                        "#/data: failed schema #/definitions/item/links/13/schema/properties/data: \"id\" is not a permitted key."
                    ]
                }
            }
        }
    ]
}

Prior to the publish, we do update the record, but there are no errors. Also prior to that update on the record, we do bulkPublish multiple linked records on the erroring record, but again, no errors are given for the linked records.

Our only thought is that the error is reporting a problem with the API itself. At one point we had mistakenly included an id in a JSON object we call schema on the linked records. This schema.id has since been removed from the JSON on the linked records, but we’re wondering if this schema.id property somehow broke the logic on the DatoCMS side as the error looks to be having issues with its own calls?

Appreciate any guidance in how we might resolve as isn’t clear we’re doing anything wrong using the JS client. Happy to share additional information.

Thanks!

Hey there @corey.gwin, and welcome to the forums! I believe we just answered same question over email sent by a colleague of yours? But to reiterate:

This is unfortunately a known bug with the old client.

datocms-client has actually been deprecated for a couple years now: datocms-client - npm

It’s replaced by the newer @datocms/cma-client-node, which has similar methods, but not 100% the same syntax (meaning there will likely be some porting work and testing involved, unfortunately): @datocms/cma-client-node - npm

In the meantime, if this is the only issue you’re running into with the old client, there is a workaround that might help. You can add {serializeRequest: false} as the third parameter for item.publish(), like this:

await client.item.publish(
    "165017661", // record ID
    {}, // body
    {}, // query string
    { serializeRequest: false } // this is the actual workaround
  );

Unfortunately, we don’t have the resources to keep updating the deprecated old client, so I’m not sure how long that workaround will be effective for (or what else might break), but hopefully that could work for you for now?

Two other workarounds, if that doesn’t work:

  • You can use the Bulk Publish method to publish just that one item, if you don’t need to specify a particular locale (i.e. you’re ok with publishing the entire record at once, including all its locales)
  • You can also run the new client with the old side by side (like per file, or per call) and gradually upgrade specific pages/methods as needed. This will slightly increase your bundle size, but would allow you to gradually upgrade to the newer client instead of doing the whole project at once.

Hope that helps! Please let me know if I can clarify anything further.

1 Like

Awesome, thanks for the quick reply, Roger.

The workaround (using serializeRequest) appears to have resolved the error for us which will be sufficient until we do an upgrade.

Thanks again!

1 Like

Great, glad that worked!

Side note: I’m going to slightly edit the thread title just in case others have the same question.

1 Like