Custom Objects store arbitrary JSON-formatted data on commercetools Composable Commerce.
Custom Objects allow you to persist data that does not fit the standard data model. This frees your application from any third-party persistence solution and means that all your data stays in one place. Custom Objects are grouped into containers, which can be used like namespaces.
20 000 000 Custom Objects can be created per Project. Learn more about this limit.Representations
CustomObject
idString | Unique identifier of the CustomObject. |
versionInt | Current version of the CustomObject. |
keyString | User-defined unique identifier of the CustomObject within the defined MinLength: container.1MaxLength: 256Pattern: ^[-_~.a-zA-Z0-9]+$ |
containerString | Namespace to group CustomObjects. Pattern:^[-_~.a-zA-Z0-9]+$ |
valueAny | Can be any JSON standard type, such as number, string, boolean, array, object, or a common API data type.
|
createdAt | Date and time (UTC) the CustomObject was initially created. |
createdByBETA | IDs and references that created the CustomObject. |
lastModifiedAt | Date and time (UTC) the CustomObject was last updated. |
lastModifiedByBETA | IDs and references that last modified the CustomObject. |
{
"id": "fa58f10a-1df3-45e2-a49c-2bf06b17d168",
"version": 1,
"createdAt": "2018-09-11T14:12:05.512Z",
"lastModifiedAt": "2018-09-11T14:12:05.512Z",
"container": "myContainer",
"key": "myKey",
"value": {
"text": {
"de": "Das ist ein Text",
"en": "This is a text"
},
"order": {
"typeId": "order",
"id": "<order-id>"
}
}
}CustomObjectDraft
versionInt | Current version of the CustomObject. |
keyString | User-defined unique identifier of the CustomObject within the defined MinLength: container.1MaxLength: 256Pattern: ^[-_~.a-zA-Z0-9]+$ |
containerString | Namespace to group CustomObjects. Pattern:^[-_~.a-zA-Z0-9]+$ |
valueAny | Can be any JSON standard type, such as number, string, boolean, array, object, or a common API data type.
|
{
"container": "myContainer",
"key": "myKey",
"value": {
"text": {
"de": "Das ist ein Text",
"en": "This is a text"
},
"order": {
"typeId": "order",
"id": "<order-id>"
}
}
}CustomObjectPagedQueryResponse
limitInt | Number of results requested. Default: 20Minimum: 0Maximum: 500 |
offsetInt | Number of elements skipped. Default: 0Maximum: 10000 |
countInt | Actual number of results returned. |
totalInt | The total number of results matching the query.
This number is an estimation that is not strongly consistent.
This field is returned by default.
For improved performance, calculating this field can be deactivated by using the query parameter withTotal=false.
When the results are filtered with a Query Predicate, total is subject to a limit. |
resultsArray of CustomObject | CustomObjects matching the query. |
CustomObjectReference
idString | Unique identifier of the referenced CustomObject. |
typeId | key-value-documentType of referenced resource. |
obj | Contains the representation of the expanded CustomObject. Only present in responses to requests with Reference Expansion for CustomObjects. |
{
"id": "4e2b758f-f259-4c14-808e-2beb126bc0f1",
"typeId": "key-value-document"
}CustomObjectKeyReference
keyString | User-defined unique identifier of the referenced CustomObject. |
typeId | key-value-documentType of referenced resource. |
containerString | The container of the referenced CustomObject. |
Get CustomObject by container and key
view_products:{projectKey}view_orders:{projectKey}view_customers:{projectKey}view_key_value_documents:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString | key of the Project. |
containerString | container of the CustomObject. |
keyString | key of the CustomObject. |
expand | Expands a value of type Reference.
If the referenced object does not exist, the API returns the non-expanded reference.The parameter can be passed multiple times. |
application/jsoncurl --get https://api.{region}.commercetools.com/{projectKey}/custom-objects/{container}/{key} -i \
--header "Authorization: Bearer ${BEARER_TOKEN}" {
"id": "d8523d32-a79d-441c-90f4-744cc342126e",
"version": 2,
"container": "test-container",
"key": "test-key",
"value": "test-value",
"createdAt": "2016-02-18T10:36:29.468Z",
"lastModifiedAt": "2016-02-18T10:36:29.571Z"
}Create or Update CustomObject
value that have null values are not saved.manage_products:{projectKey}manage_orders:{projectKey}manage_customers:{projectKey}manage_key_value_documents:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString | key of the Project. |
expand | Expands a value of type Reference.
If the referenced object does not exist, the API returns the non-expanded reference.The parameter can be passed multiple times. |
application/jsonapplication/jsonapplication/jsoncurl https://api.{region}.commercetools.com/{projectKey}/custom-objects -i \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header 'Content-Type: application/json' \
--data-binary @- << DATA
{
"container" : "test-container",
"key" : "test-key",
"value" : "test-value"
}
DATA{
"id": "d8523d32-a79d-441c-90f4-744cc342126e",
"version": 2,
"container": "test-container",
"key": "test-key",
"value": "test-value",
"createdAt": "2016-02-18T10:36:29.468Z",
"lastModifiedAt": "2016-02-18T10:36:29.571Z"
}Query CustomObjects
view_products:{projectKey}view_orders:{projectKey}view_customers:{projectKey}view_key_value_documents:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString | key of the Project. |
containerString | container of the CustomObjectPagedQueryResponse. |
where | id, key, version, createdAt, and lastModifiedAt can be used as predicate.
value can also be used as predicate, but is not checked for validity.
For example: value(exampleNumber > 1233) or value(exampleObject(exampleBoolean = true)).The parameter can be passed multiple times. |
sort | Query results can be sorted by container, key, createdAt, and lastModifiedAt.The parameter can be passed multiple times. |
expand | Expands a value of type Reference.
If the referenced object does not exist, the API returns the non-expanded reference.The parameter can be passed multiple times. |
limitInt | Number of results requested. Default: 20Minimum: 0Maximum: 500 |
offsetInt | Number of elements skipped. Default: 0Maximum: 10000 |
withTotalBoolean | Controls the calculation of the total number of query results. Set to false to improve query performance when the total is not needed.Default: true |
var.<varName>String | Predicate parameter values. The parameter can be passed multiple times. |
CustomObjectPagedQueryResponse
asapplication/jsoncurl --get https://api.{region}.commercetools.com/{projectKey}/custom-objects/{container} -i \
--header "Authorization: Bearer ${BEARER_TOKEN}"{
"limit": 20,
"offset": 0,
"count": 2,
"total": 2,
"results": [
{
"id": "f584ebbb-3805-43f3-80c8-76f98b2c18b5",
"version": 5,
"container": "test-container",
"key": "ac390383-370f-43f8-a534-db1604cb96a8",
"value": {
"name": "commercetools",
"slug": "commercetools",
"geoLocation": {
"type": "Point",
"coordinates": [13.412119019109015, 52.50103330534661]
}
},
"createdAt": "2015-05-28T09:48:35.098Z",
"lastModifiedAt": "2015-07-01T15:58:36.930Z"
},
{
"id": "d8523d32-a79d-441c-90f4-744cc342126e",
"version": 2,
"container": "test-container",
"key": "test-key",
"value": "test-value",
"createdAt": "2016-02-18T10:36:29.468Z",
"lastModifiedAt": "2016-02-18T10:36:29.571Z"
}
]
}Check if CustomObject exists
Check if CustomObject exists by Query Predicate
200 status if any CustomObjects match the query predicate, or a 404 status otherwise.view_products:{projectKey}view_orders:{projectKey}view_customers:{projectKey}view_key_value_documents:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString | key of the Project. |
where |
curl --head https://api.{region}.commercetools.com/{projectKey}/custom-objects -i \
--header "Authorization: Bearer ${BEARER_TOKEN}" Delete CustomObject by Container and Key
manage_products:{projectKey}manage_orders:{projectKey}manage_customers:{projectKey}manage_key_value_documents:{projectKey}regionString | Region in which the Project is hosted. |
projectKeyString | key of the Project. |
containerString | container of the CustomObject. |
keyString | key of the CustomObject. |
versionInt | Last seen version of the resource. |
expand | Expands a value of type Reference.
If the referenced object does not exist, the API returns the non-expanded reference.The parameter can be passed multiple times. |
dataErasureBoolean | To erase all related personal data in compliance with GDPR, set to true.Default: false |
application/jsoncurl -X DELETE https://api.{region}.commercetools.com/{projectKey}/custom-objects/{container}/{key} -i \
--header "Authorization: Bearer ${BEARER_TOKEN}"{
"id": "d8523d32-a79d-441c-90f4-744cc342126e",
"version": 2,
"container": "test-container",
"key": "test-key",
"value": "test-value",
"createdAt": "2016-02-18T10:36:29.468Z",
"lastModifiedAt": "2016-02-18T10:36:29.571Z"
}