Errors in trying to update an entry

I’ve been migrating existing data over for a while now and everything has been going smoothly, but now I am attempting to update existing content via the API I seem to have hit a roadblock.

I am using the http approach and following the documentation here:-

But I am having trouble with the request. I have tried various schemas, this is where I am currently…

{
	"data": {
		"relationships": {
			"id": "1366008", (**The ID of the model**)
			"type": "item_type"
		},
		"type": "item",
		"attributes": {
			"cities": [
				{
					"Id": "70401053" (**The id of the item I wish to have associated with the item I am updating**)
				}
			]
		},
		"id": "87828345" (**The id of the item I wish to update**)
	}
}

But I am receiving an error response …

{
	"data": [
		{
			"id": "a0cd05",
			"type": "api_error",
			"attributes": {
				"code": "INVALID_FORMAT",
				"details": {
					"messages": [
						"#/data: failed schema #/definitions/item/links/3/schema/properties/data: \"id\" is not a permitted key.",
						"#/data/relationships: failed schema #/definitions/item/links/3/schema/properties/data/properties/relationships: \"id\", \"type\" are not permitted keys.",
						"#/data/relationships: failed schema #/definitions/item/links/3/schema/properties/data/properties/relationships: \"item_type\" wasn't supplied."
					]
				}
			}
		}
	]
}

Of these errors, the one puzzling me the most is “Id is not a permitted key”, and yet it appears as a field in the example given on the documentation?

Any help in letting me know what the schema should look like in order to get a successful response would be appreciated.

It might be useful if I could have the full URLs to the schema definitions mentioned in the error?

1 Like

Hello @andrew.ravenwood

There are a couple problems with the request:

The request should be a PUT request, (with all the headers you probably already had included) but to the URL https://site-api.datocms.com/items/RECORD_ID if we want to update an existing record.
If you just do the put request to https://site-api.datocms.com/items the “id” key is rejected, as that URL is only for the creation of records, and you can’t specify an id when creating a record.

So on your case, the PUT request should be to https://site-api.datocms.com/items/87828345

Other two problems with the request were:

  1. The “relationship” key here is not necessary, so you can just remove it
  2. As it is a Multiple links field, the “cities” value should be an array of strings, each string being an id of a city record.

So your request will end up being:


PUT https://site-api.datocms.com/items/87828345

(headers...)

{
    "data": {
        "id": "87828345",
        "type": "item",
        "attributes": {
            "cities": [
                "70401053"
            ]
        }
    }
}

Hope this helps!

Hi,

As soon as I read the first line in your response I realised what was wrong! So busy looking at the details I missed the most basic part of the request.

This is very helpful, thank you.

1 Like