How to create a structured Text record with an inlineItem using Content Managment API?

Hey guys, I am trying to create a structured text record with an inlineItem reference
Using the Content Managment API but I really don’t get it.

The documentation only reference to block references but not for inlineItems (links).

I’m trying to pass the inlineItem directly as says Structured Text and Dast format — DatoCMS

  {
    "type": "inlineItem",
    "item": record.id
  },

but I’m getting a 422 Unprocessable Entity Error

Error: POST https://site-api.datocms.com/items: 422 Unprocessable Entity

[
  {
    "id": "e2a0f0",
    "type": "api_error",
    "attributes": {
      "code": "INVALID_FIELD",
      "details": {
        "field": "content",
        "field_id": "3850019",
        "field_label": "Content",
        "field_type": "structured_text",
        "errors": [
          "#/children/2: failed schema #/definitions/Root/properties/children/items: No subschema in \"anyOf\" matched."
        ],
        "code": "INVALID_FORMAT",
        "message": "Value not acceptable for this field type",

Any Ideas? I don’t know if Content Managment API allow migrations with inlineItems or I’m doing it wrong.

Thanks!

Yes! I was doing it wrong :sweat_smile:

Following the dast schema https://site-api.datocms.com/docs/dast-schema.json I see the inlineItems need to be children from a paragraph element (it make sense)


    "ParagraphType": {
      "type": "string",
      "const": "paragraph"
    },
    "InlineNode": {
      "anyOf": [
        {
          "$ref": "#/definitions/Span"
        },
        {
          "$ref": "#/definitions/Link"
        },
        {
          "$ref": "#/definitions/ItemLink"
        },
        {
          "$ref": "#/definitions/InlineItem"
        }
      ]
    },

Then the above code should be

          {
            "type": "paragraph",
            "children": [
              {
                "type": "inlineItem",
                "item": record.id
              },
            ]
          },

An voila! “Successfully run 1 migration scripts

I hope it helps

Perhaps I would recommend putting more practical examples at Structured Text and Dast format - DatoCMS
For example, if an element needs to be the child of another, it might be interesting to put the example code with all the context.

For example, in the case

{
  "type": "inlineItem",
  "item": "74619345"
}

Maybe it makes more sense


          {
            "type": "paragraph",
            "children": [
              {
                "type": "inlineItem",
                "item": "74619345"
              },
            ]
          },

By this way it helps to understand that it must be a son of paragraph. This could apply to the rest as well that need to be children of another

Thanks

1 Like