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!