Creating a record with JS client?

I’m banging my head against a wall with this seemingly simple task. I’m following the docs here: https://www.datocms.com/docs/content-management-api/resources/item/create but getting an error.

Here’s my code:

import {buildClient} from '@datocms/cma-client-browser'
const client = buildClient({apiToken: 'mykey'})

My key is associated with a role which has permissions to create my “submission” content type.

const record = await client.items.create({
	item_type: {type: 'submission', id: '1668821'},
	name: 'lorem',
})

I then get the error:

[
  {
    "id": "96ae3c",
    "type": "api_error",
    "attributes": {
      "code": "INVALID_FORMAT",
      "details": {
        "messages": [
          "#/data/relationships/item_type/data/type: failed schema #/definitions/item_type/definitions/data/properties/type: submission does not match /^item_type$/."
        ]
      }
    }
  }
]

Am I doing something stupid, or are the docs just wrong? There’s so little complexity here, I can’t see anywhere I could have gone wrong.

Try with:

const record = await client.items.create({
	item_type: {type: 'item_type', id: '1668821'},
	name: 'lorem',
})
1 Like