`content_in_locales` field in publish API function

Describe the issue:

  • Please include any relevant error messages, screenshots, and troubleshooting you’ve already tried.

Hi there! I’m trying to use the API to publish a record. According to the Content Management Api docs, I’m using:

    await client.items.publish(
      itemId,
      {
        content_in_locales: [''],
        non_localized_content: true,
      },
      {
        recursive: true,
      }
    );

But I’m getting an unprocessable entity error:

22 Unprocessable Entity

[
  {
    "id": "xxxxxx",
    "type": "api_error",
    "attributes": {
      "code": "INVALID_FIELD",
      "details": {
        "field": "content_in_locales",
        "code": "VALIDATION_INVALID"
      }
    }
  }
]

When I adjust content_in_locales to be null, the API call goes though, but my build fails saying that content_in_locales must be an array of strings.

(Optional) Can you provide a link to the item, model, or project in question?

(Optional) Do you have any sample code you can provide?

@pranathi, sorry, it does seem like there is some wonky issue with this endpoint! It may be a bug. I’ll report it to the devs right away.

In the meantime, there might be a workaround if your project doesn’t currently have multiple locales (or you don’t mind publishing all of them). Despite what the documentation says, could you please try this:

await client.items.publish(itemId, null, {recursive: true});

(Just leave out the body param altogether, despite what the docs say).

That should let the request go through (tested with cma-client-node @ 3.0.6). I’ll follow up with the devs and let you know ASAP if we can fix the underlying bug. Sorry about that!

I’ve reported the issue to the devs, and will post back here once we have a resolution. In the meantime, just wanted to add a bit more nuance to the workaround:

  • If you want to publish the record as a whole (all locales), just leave out the body{} parameter altogether (i.e., don’t include either content_in_locales or non_localized_content)
  • If you want to publish only a specific locale, you MUST include BOTH:
    • content_in_locales with a valid array of locales, like ['en', 'it'] (no empty strings or nulls)
    • non_localized_content MUST be explicitly set (to either true or false, depending on what you want)
    • If you provide content_in_locales WITHOUT non_localized_content, it will be ignored and ALL locales will be published. This is probably a bug.

Again, this is just an observation of how the workaround functions right now – not how the endpoint is probably intended to function. I’ll post back once we have more information.

Sorry about that!!

The new doc page should make everything much more clear: Publish a record - Record - Content Management API