Product Updates

DatoCMS changelog for new features and general improvements
Content Management API

Creation of new records via API no longer requires to specify all fields

November 26th, 2021

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:

1
const { SiteClient } = require("datocms-client");
2
3
const client = new SiteClient("YOUR-API-TOKEN");
4
5
const record = await client.items.create({
6
itemType: "1234",
7
requiredField: "Lorem ipsum",
8
optionalField1: null,
9
optionalField2: null,
10
optionalField3: null,
11
optionalField4: null,
12
optionalField5: null,
13
optionalField6: null,
14
optionalField7: null,
15
optionalField8: null,
16
optionalField9: null,
17
});

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!

Start using DatoCMS today
According to Gartner 89% of companies plan to compete primarily on the basis of customer experience this year. Don't get caught unprepared.
  • No credit card
  • Easy setup
Subscribe to our newsletter! đź“Ą
One update per month. All the latest news and sneak peeks directly in your inbox.
support@datocms.com ©2024 Dato srl, all rights reserved P.IVA 06969620480