Hi there!
Iām writing a cli tool that will clone some Dato objects from one project to another, Iām using the latest datocms-client for node (3.5.6) and Iām stuck on some validation errors that I keep gettingā¦
If I try to create the complete object, I get this error:
seems like the postCover attribute is missing even though you can see the object Iām trying to create below has a proper object created with the helper buildModularBlock.
{
itemType: '418355',
title: 'Test TK',
abstract: '<p>Tk</p>',
category: '11414710',
postCover: [ { type: 'item', attributes: [Object], relationships: [Object] } ],
previewImage: { uploadId: '28382383' },
slug: 'tk-test',
seoFields: { title: 'TK', description: 'TK', image: '28382383' },
relatedPosts: [],
tags: [],
importToCloud: false,
showSeeAlso: false,
publishedAuthorName: 'Nome autore pubblicato',
editorName: 'Nome autore pubblicato',
originalPublicationDate: '2021-10-26T10:54:08.406-04:00',
originalPostId: 'usa:24560128',
previewLink: null,
postBlocks: [ { type: 'item', attributes: [Object], relationships: [Object] } ]
}
This is the complete error Iām getting from the client:
ApiException: 422 MISSING_FIELDS (details: {"required_fields":["cover_image"],"missing_fields":["cover_image"],"locale":null})
at /xxx/node_modules/datocms-client/lib/Client.js:224:33
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /xxx/src/routes/syndicator.js:1281:32
Caused By:
Error
at Object.get (/xxx/node_modules/datocms-client/lib/utils/generateClient.js:123:28)
at /xxx/src/routes/syndicator.js:1281:62 {
body: { data: [ [Object], [Object], [Object] ] },
headers: [Object: null prototype] {
date: [ 'Tue, 26 Oct 2021 15:12:07 GMT' ],
'content-type': [ 'application/json; charset=utf-8' ],
'transfer-encoding': [ 'chunked' ],
connection: [ 'close' ],
'cf-ray': [ '6a449f001920e8f7-MXP' ],
'access-control-allow-origin': [ '*' ],
'cache-control': [ 'no-cache' ],
'content-encoding': [ 'gzip' ],
'strict-transport-security': [ 'max-age=15552000; includeSubDomains; preload' ],
vary: [ 'Accept,Accept-Encoding' ],
via: [ '1.1 vegur' ],
'cf-cache-status': [ 'DYNAMIC' ],
'access-control-allow-credentials': [ 'true' ],
'access-control-allow-headers': [
'authorization, content-type, x-environment, x-site-domain, x-api-version, user-agent, x-session-id'
],
'access-control-allow-methods': [ 'GET, POST, PUT, OPTIONS, DELETE' ],
'access-control-expose-headers': [ 'x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset' ],
'access-control-max-age': [ '1728000' ],
'expect-ct': [
'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"'
],
'referrer-policy': [ 'strict-origin-when-cross-origin' ],
'x-api-version': [ '3' ],
'x-content-type-options': [ 'nosniff' ],
'x-download-options': [ 'noopen' ],
'x-environment': [ 'main' ],
'x-frame-options': [ 'SAMEORIGIN' ],
'x-permitted-cross-domain-policies': [ 'none' ],
'x-queue-time': [ '0ms' ],
'x-ratelimit-limit': [ '60' ],
'x-ratelimit-remaining': [ '56' ],
'x-request-id': [ '220c3f80-6548-4277-85df-0dd0ba04105d' ],
'x-runtime': [ '0.080271' ],
'x-xss-protection': [ '1; mode=block' ],
server: [ 'cloudflare' ]
},
statusCode: 422,
statusText: 'Unprocessable Entity',
requestUrl: 'https://site-api.datocms.com/items',
requestMethod: 'POST',
requestHeaders: {
'content-type': 'application/json',
accept: 'application/json',
authorization: 'Bearer xxx',
'user-agent': 'js-client v3.5.6',
'X-Api-Version': '3'
},
requestBody: '{"data":{"type":"item","attributes":{"title":"Test TK","abstract":"<p>Tk</p>","category":"11414710","post_cover":[{"type":"item","attributes":{"cover_image":{"upload_id":"28382385"}},"relationships":{"item_type":{"data":{"id":"418358","type":"item_type"}}}}],"preview_image":{"upload_id":"28382383"},"slug":"tk-test","seo_fields":{"title":"TK","description":"TK","image":"28382383"},"related_posts":[],"tags":[],"import_to_cloud":false,"show_see_also":false,"published_author_name":"Nome autore pubblicato","editor_name":"Nome autore pubblicato","original_publication_date":"2021-10-26T10:54:08.406-04:00","original_post_id":"usa:24560128","preview_link":null,"post_blocks":[{"type":"item","attributes":{"content":["<p><span>Il generatore di toni online può essere utilizzato per creare segnali Dual Tone Multi Frequency (DTMF) comunemente ascoltati sui tasti del telefono. Ogni tono è semplicemente la somma di due onde sinusoidali. Fare clic e tenere premuti i pulsanti del tastierino per ascoltare ogni tono.</span></p>"]},"relationships":{"item_type":{"data":{"id":"418358","type":"item_type"}}}}]},"relationships":{"item_type":{"data":{"type":"item_type","id":"418355"}}}}}'
}
If instead, I try to create the object without the postBlocks field, the creation went through and I get no 422 errors back, just plain beautiful 200. 
This is the object Iām able to create:
{
itemType: '418355',
title: 'Test TK',
abstract: '<p>Tk</p>',
category: '11414710',
postCover: [ { type: 'item', attributes: [Object], relationships: [Object] } ],
previewImage: { uploadId: '28382950' },
slug: 'tk-test',
seoFields: { title: 'TK', description: 'TK', image: '28382950' },
relatedPosts: [],
tags: [],
importToCloud: false,
showSeeAlso: false,
publishedAuthorName: 'Nome autore pubblicato',
editorName: 'Nome autore pubblicato',
originalPublicationDate: '2021-10-26T10:54:08.406-04:00',
originalPostId: 'usa:24560128',
previewLink: null,
postBlocks: [] // <--- THIS IS THE DIFFERENCE
}
As you can see the postCover attribute is the same on both tests, the only thing that changes and prevents the item creation is the content of postBlocks.
Any help would be really appreciated because Iāve tried dozens of times and Iām stuck.
Thank you very much,
Cheers!

