JSON Data Format used in WebAPI calls (technical)
When reading or writing data to/from the Headless WebAPI the data format used is JSON. Here are the basics:
Read Single Item is Super-Simple JSON
Here's an example of a BusinessUnit item:
{
"Name": "Web",
"Description": "<p>We create websites!</p>",
"Id": 19403,
"Guid": "1252c52c-30e4-4c9f-8d45-e094160ca251",
"Title": "Web",
"Modified": "2021-02-25T20:32:52.94Z",
"Created": "2021-02-18T20:47:58.827Z"
}
Some notes
- All the value fields have their real names, usually uppercase as that's how the fields are typically named
- A few internal fields are also included
Id(int)Title(string)Modified(date)Created(date)Guid(string with GUID) - this is only supplied on queries or if the REST API requests includes a?includeGuid=true
- Dates are transferred as strings, using the international ISO format
- Html strings contain the real html
Read Lists: Arrays of Items
[
{
"Name": "Web",
"Description": "<p>We create websites!</p>",
"Id": 19403,
"Guid": "1252c52c-30e4-4c9f-8d45-e094160ca251",
"Title": "Web",
"Modified": "2021-02-25T20:32:52.94Z",
"Created": "2021-02-18T20:47:58.827Z"
},
{
"Name": "Dev",
"Description": "<p>Our development unit</p>",
"Id": 19404,
"Guid": "c89cb53b-0f7b-441a-9e6c-5467dd9322e9",
"Title": "Dev",
"Modified": "2021-02-25T18:02:52.327Z",
"Created": "2021-02-18T20:47:58.827Z"
},
{
"Name": "Eff",
"Description": "<p>Everything regarding efficiency - like <a href=\"https://sphosting.ch\" target=\"_blank\" rel=\"noopener\">SharePoint</a>, Word & Excel automation, <a href=\"https://azing.org\" target=\"_blank\" rel=\"noopener\">azing.org</a></p>",
"Id": 19405,
"Guid": "fa4a1de9-adf5-4e1d-ab70-63281b3e797b",
"Title": "Eff",
"Modified": "2021-02-25T18:03:12.84Z",
"Created": "2021-02-18T20:47:58.827Z"
}
]
Write / PUT has the Same Data Format
To create data or update it, use the identical format. Some notes:
- When creating, the ID must be blank (otherwise an update is assumed)
- When creating, the Guid is usually blank and will be generated automatically (see special notes below)
Special System Properties when Saving
When creating or updating data, there are some system properties you can also set, which affect how things are saved
EntityGuid on Create (ca. v8)
You can provide an EntityGuid if necessary, for example when other code needs to know the Guid before creating.
This would then be saved and returned on the Guid property on the next call.
PublishState Controls Publishing (v13.03)
If you set the property PublishState it can have these values and effects:
nullor""will save new as is preset by permissions; on update it will leave the existing state unchangedtrue,"true",1will always set the published to true (if permissions allow)false,"false",0will alwyays set published to false"draft"will set published to false; if it's an update and there was a published one before, that will remain published
For Determines Metadata-Target (ca. v11)
For can contain metadata headers to anchor this item to another thing. Will only affect new data, and be ignored on updates.
This is the schema of this object
{
TargetType: int; // one of known target types
Number?: number; // Key if it's a number key
String?: string; // Key if it's a string ey
Guid?: string; // Guid if it's a GUID key
}
Note that you must provide one of the keys, othewise it will fail.
- See also Metadata Target Types
- See also SxcData
ParentRelationship Adds Item to a Parent (v13.03)
If your data has a property ParentRelationship with these fields:
Parent- a GUID to the parentField- the name of the field it should be added to (must be an entity-field)Index- the location it should be added to in that field which is a list of items
Then upon creating the new item, it will also be added to that parent and it's list of items.
Read / Write Multi-Language Data
This does not exist yet as a simple REST API but is a planned feature for 2022. For now, create your own WebApi if you need this.
History
- REST API added ca. v7 on the path
/app/content - Ability to also set
EntityGuidadded ca. v8 Forfeature added ca. v11- primary path changed to
/app/data/ PublishStateadded v13.03ParentRelationshipadded v13.03