Creation of new records via API no longer requires to specify all fields
This change was long overdue, and we're glad we were able to address it! 🥳
Suppose you have ie. a model with 10 fields, 9 of which are optional. Until now, when creating a record, you were required to specify... all 10 fields. If you didn't want any value for the optional ones, you were required to pass a null
value in any case, or the API call would fail:
const { SiteClient } = require("datocms-client");
const client = new SiteClient("YOUR-API-TOKEN");
const record = await client.items.create({ itemType: "1234", requiredField: "Lorem ipsum", optionalField1: null, optionalField2: null, optionalField3: null, optionalField4: null, optionalField5: null, optionalField6: null, optionalField7: null, optionalField8: null, optionalField9: null,});
In addition to being redundant and inconvenient, this was a maintainability problem over time, because when a new optional field gets added on the model, you need adapt every script and add that null
value. Well, now optional fields can be omitted from the payload during creation:
const record = await client.items.create({ itemType: "1234", requiredField: "Lorem ipsum",});
Nice, simple and clean. Happy friday!