Hook action

A hook action specifies what should happen when a hook is executed.

Attributes

Attribute Type Description Required
action_type string enum: update-resource The type of action that should be performed when a hook is triggered.
values array of objects An array of objects containing specific data depending on the action_type.

Different action_types might require differently formatted objects as values in the future when more action_types are supported.

Update resource

At this time, the only supported action_type is update-resource. This action type is used to update the resource that triggered the hook with the specified values. The format for a value object for action_type update-resource is shown in the table below.

Attribute Type Description Required
pointer string JSON pointer formatted string pointing to the resource property that should be assigned.
value string, integer, float, boolean, array or object The new value that the resource property, resolved by the pointer attribute, should get.

Using a hook to update a resource will not overwrite already set resource properties!

Examples

The example hook action below will set the target resource’s description attribute to Baseball cap. This only works if the resource that triggered this hook, does not already have the description attribute set!

{
  "action_type": "update-resource",
  "values": [
    {
      "pointer": "attributes/description",
      "value": "Baseball cap"
    }
  ]
}

It is possible to add multiple value objects to a hook action.
The following example sets the service relationship of a shipment resource by setting both the type and id of the service relationship using two values:

{
  "action_type": "update-resource",
  "values": [
    {
      "pointer": "relationships/service/data/type",
      "value": "services"
    },
    {
      "pointer": "relationships/service/data/id",
      "value": "69460e06-4dfe-440a-b349-83c45fc5ff10"
    }
  ]
}
12-03-2019