States
The commercetools Platform allows you to model States of Orders, Line Items, Products, Reviews, and Payments to define finite state machines reflecting the business logic you'd like to implement.
States can be combined together by defining transitions
between each State. transitionState
update actions are validated to ensure the transition complies with the workflow definition.
If the transitions
field is not set, no validation is performed. This is useful when an external system executes the workflow and the current State is to be saved.
By default, each Project has a builtin
, initial
, and LineItemState
defined for LineItems and CustomLineItems.
Representations
State
id String | Unique ID of the State. |
version Int | Current version of the State. |
key String | User-defined unique identifier for the State. |
createdAt | Date and time (UTC) the State was initially created. |
createdBy BETA | Present on resources created after 1 February 2019 except for events not tracked. |
lastModifiedAt | Date and time (UTC) the State was last updated. |
lastModifiedBy BETA | Present on resources created after 1 February 2019 except for events not tracked. |
type | Indicates to which resource or object types the State is assigned to. |
name | Name of the State. |
description | Description of the State. |
initial Boolean |
|
builtIn Boolean |
|
roles Array of StateRoleEnum | Roles the State can fulfill for Reviews and Line Items. |
transitions Array of StateReference |
|
StateDraft
key String | User-defined unique identifier for the State. |
type | Specify to which resource or object type the State is assigned to. |
name | Name of the State. |
description | Description of the State. |
initial Boolean | Set to true |
roles Array of StateRoleEnum | If suitable, assign predifined roles the State can fulfill in case the State's |
transitions Array of StateResourceIdentifier | Define the list of States of the same
|
StatePagedQueryResponse
PagedQueryResult with results
containing an array of State.
limit Int | Number of results requested in the query request. |
offset Int | Offset supplied by the client or the server default. It is the number of elements skipped, not a page number. |
count Int | Actual number of results returned. |
total Int | 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 |
results Array of State | States matching the query. |
StateReference
id String | Unique ID of the referenced State. |
typeId String | "state" |
obj | Contains the representation of the expanded State. Only present in responses to requests with Reference Expansion for State. |
StateResourceIdentifier
ResourceIdentifier to a State.
StateTypeEnum
Resource or object type the State can be assigned to.
OrderState
Used by Orders.
LineItemState
Used by LineItems and CustomLineItems in Carts and Orders.
ProductState
Used by Products.
ReviewState
Used by Reviews.
PaymentState
Used by PaymentStatus in Payments.
StateRoleEnum
For some resource types, a State can fulfill the following predefined roles:
ReviewIncludedInStatistics
If a Review's
state
has this role itsrating
is taken into account for ReviewRatingStatistics. This role only applies for theReviewState
StateTypeEnum.Return
Used by Orders in the update action transitionLineItemState. This role only applies for the
LineItemState
StateTypeEnum.
Get State
Get State by ID
Deprecated OAuth 2.0 scope: view_orders:{projectKey}
view_states:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String |
|
id String |
|
expand | The parameter can be passed multiple times. |
200State
curl -X GET https://api.{region}.commercetools.com/{projectKey}/states/{id} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
Get State by Key
Deprecated OAuth 2.0 scope: view_orders:{projectKey}
view_states:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String |
|
key String |
|
expand | The parameter can be passed multiple times. |
200State
curl -X GET https://api.{region}.commercetools.com/{projectKey}/states/key={key} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
Query States
Deprecated OAuth 2.0 scope: view_orders:{projectKey}
view_states:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String |
|
where | The parameter can be passed multiple times. |
/^var[.][a-zA-Z0-9]+$/ Any string parameter matching this regular expression | Predicate parameter values. The parameter can be passed multiple times. |
sort | The parameter can be passed multiple times. |
expand | The parameter can be passed multiple times. |
limit Int | Number of results returned. |
offset Int | Number of results skipped. |
withTotal Boolean | Controls the calculation of the total number of query results. Set to |
curl -X GET https://api.{region}.commercetools.com/{projectKey}/states -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
Create State
Deprecated OAuth 2.0 scope: manage_orders:{projectKey}
manage_states:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String |
|
expand | The parameter can be passed multiple times. |
201State
curl -X POST https://api.{region}.commercetools.com/{projectKey}/states -i \--header 'Authorization: Bearer ${BEARER_TOKEN}' \--header 'Content-Type: application/json' \--data-binary @- << DATA{"key" : "test-state","type" : "ProductState","roles" : [ ],"initial" : true}DATA
Update State
Update State by ID
Deprecated OAuth 2.0 scope: manage_orders:{projectKey}
manage_states:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String |
|
id String |
|
expand | The parameter can be passed multiple times. |
version Int | Expected version of the State on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned. |
actions Array of StateUpdateAction | Update actions to be performed on the State. |
200State
curl -X POST https://api.{region}.commercetools.com/{projectKey}/states/{id} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}' \--header 'Content-Type: application/json' \--data-binary @- << DATA{"version" : 1,"actions" : [ {"action" : "setName","name" : {"en" : "New Name"}} ]}DATA
Update State by Key
Deprecated OAuth 2.0 scope: manage_orders:{projectKey}
manage_states:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String |
|
key String |
|
expand | The parameter can be passed multiple times. |
version Int | Expected version of the State on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned. |
actions Array of StateUpdateAction | Update actions to be performed on the State. |
200State
curl -X POST https://api.{region}.commercetools.com/{projectKey}/states/key={key} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}' \--header 'Content-Type: application/json' \--data-binary @- << DATA{"version" : 1,"actions" : [ {"action" : "setName","name" : {"en" : "New Name"}} ]}DATA
Update actions
Change State key
key String | New value to set. Must not be empty. |
action String | "changeKey" |
{"action" : "changeKey","key" : "ChangedStateKey"}
Set State name
action String | "setName" |
name | Value to set. If empty, any existing value will be removed. |
{"action" : "setName","name" : {"de" : "State Name","en" : "State name"}}
Set State description
action String | "setDescription" |
description | Value to set. If empty, any existing value will be removed. |
{"action" : "setDescription","description" : {"de" : "State Beschreibung","en" : "State description"}}
Change State type
action String | "changeType" |
type | Resource or object types the State shall be assigned to. Must not be empty. |
{"action" : "changeType","type" : "ReviewState"}
Change initial State
action String | "changeInitial" |
initial Boolean | Set to |
{"action" : "changeInitial","initial" : false}
Set transitions
action String | "setTransitions" |
transitions Array of StateResourceIdentifier | Value to set. If empty, any existing value will be removed. Possible transformations of the current State to other States of the same If When performing a |
{"action" : "setTransitions","transitions" : [ {"typeId" : "state","id" : "{{state-id}}"}, {"typeId" : "state","id" : "{{state-id2}}"} ]}
Set State roles
action String | "setRoles" |
roles Array of StateRoleEnum | Value to set. If empty, any existing value will be removed. |
{"action" : "setRoles","roles" : [ "ReviewIncludedInStatistics" ]}
Add State roles
action String | "addRoles" |
roles Array of StateRoleEnum | Value to append to the array. |
{"action" : "addRoles","roles" : [ "ReviewIncludedInStatistics" ]}
Remove State roles
action String | "removeRoles" |
roles Array of StateRoleEnum | Roles to remove from the State. |
{"action" : "removeRoles","roles" : [ "ReviewIncludedInStatistics" ]}
Delete State
Delete State by ID
Deprecated OAuth 2.0 scope: manage_orders:{projectKey}
manage_states:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String |
|
id String |
|
expand | The parameter can be passed multiple times. |
version Int | Last seen version of the resource. |
200State
curl -X DELETE https://api.{region}.commercetools.com/{projectKey}/states/{id}?version={version} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'
Delete State by Key
Deprecated OAuth 2.0 scope: manage_orders:{projectKey}
manage_states:{projectKey}
region String | Region in which the Project is hosted. |
projectKey String |
|
key String |
|
expand | The parameter can be passed multiple times. |
version Int | Last seen version of the resource. |
200State
curl -X DELETE https://api.{region}.commercetools.com/{projectKey}/states/key={key}?version={version} -i \--header 'Authorization: Bearer ${BEARER_TOKEN}'