REST API
The REST API for the anticipated.io service is a traditional REST API and is the only way to create events in the system.
Authentication
Authentication is supported via API Key. The API key is a secret that is used to authenticate your request and provided in the header of the HTTP request. You can create an API key by visiting the API Keys page.
The API Key is provided in the HTTP header. Please send the header key X-API-Key with the value of the API Key. Here is an example of a create call using the header value with Curl:
curl -i \ --header "Content-Type: application/json" \ --header "X-API-Key: FobaLivkMxCRx4V4b4DB6yUBbRyY2BwTYaBMfexLA7Vq" \ --request POST \ --data '{ "type": "json", "when": "in 20 seconds", "details": { "document": { "id": "Y9yJ4qDDMpHGmmYboWt4ZE", "customer": "MJvrmWjJ3zZe7pPWHWta7r" }, "url": "https://diagnostics.anticipated.io/v1/post", "method": "post", "headers": [] } }' \ https://api.anticipated.io/v1/eventTypes of Events
There are three types of events in the system:
- JSON
- XML
- Amazon SQS
These event types are denoted as 'json', 'xml' or 'sqs' in the request.
Each event has specific requirements. For web hook style events such as JSON and XML each event requires a URL and a method for making the call when the event triggers. The SQS event only requires a queue URL and a document payload (in JSON).
Create Event
POST to /v1/event
https://api.anticipated.io/v1/eventCreates an event in the anticipated.io system. To create an event send a JSON payload via POST to https://api.anticipated.io/v1/event
Parameter Description Required type Type of event to create. Allowable values are json, xml, or sqs when When the event should be triggered. A date/time string in an ISO (ISO 8601) format or a relative time format. Examples of usable formats are: "2022-06-15T00:00:00Z", "in 20 minutes", or "2022-06-17T02:02:28Z" details An object defining the information about the event. There are three different details payloads. One for the json event, xml event and one for the sqs event. Each of the details are defined below. JSON Details Payload
Parameter Description Required details.url The URL you want the triggered event to contact. This can be any URL including query string values. details.method The method of HTTP request (the verb) to use: get, post, put, delete details.document An object provided with the triggered event. This object can be used to pass data to the service. It is static data and most likely will have data related to the event - example: {"document": {"customer":"82345"}}
Note: the document is NOT sent if the method chosen is get due to protocol requirements.
details.headers Additional headers to use during the JSON request. This is an object with key/value pairs. An example might be: {"headers": [{"x-customer":"82345"}]}
XML Details Payload
Parameter Description Required details.url The URL you want the triggered event to contact. This can be any URL including query string values. details.method The method of HTTP request (the verb) to use: get, post, put, delete details.document An string of XML to be provided with the triggered event. This XML string can be used to pass data to the service. It is static data and most likely will have data related to the event - example: <xml><customer>82345</customer></xml>
Note: the document is NOT sent if the method chosen is get due to protocol requirements.
details.headers Additional headers to use during the JSON request. This is an object with key/value pairs. An example might be: {"headers": [{"x-customer":"82345"}]}
SQS Details Payload
Parameter Description Required details.url The url of the AWS SQS Queue. details.document An object provided with the triggered event. This object can be used to pass data to the service. It is static data and most likely will have data related to the event - example: {"document": {"customer":"82345"}}
Note: the document is NOT sent if the method chosen is get due to protocol requirements.
Example Payload
Here is an example payload to create a webhook event using JSON. We will schedule this 32 days from now and send it to our web service via https://myplatform.com/events/32days. In order to process this event we need to know two things: the Order ID and the Customer Number so we create a "document" with that information in it. This information is persisted and sent in the event.
{ "type": "json", "when": "32 days from now", "details": { "document": { "id": "Y9yJ4qDDMpHGmmYboWt4ZE", "customer": "MJvrmWjJ3zZe7pPWHWta7r" }, "url": "https://myplatform.com/events/32days", "method": "post", "headers": [] } }Response from the anticipated.io system will look like this:
{ "request": { "id": "HPUJTTKmvp3UYgyECjspUb" }, "context": { "user": null, "company": "6gtGBDj6jEre4xgFCAgrnj" }, "message": "", "now": "2022-06-17T15:55:31.125Z", "event": { "id": "TBqDft2LrULaSxCzpMDXc6", "company": "6gtGBDj6jEre4xgFCAgrnj", "type": "json", "when": "2022-07-18T15:55:31.085Z", "created": "2022-06-16T15:55:31.085Z", "details": { "document": { "id": "Y9yJ4qDDMpHGmmYboWt4ZE", "customer": "MJvrmWjJ3zZe7pPWHWta7r" }, "url": "https://myplatform.com/events/32days", "method": "post", "headers": [] } } }When the event triggers our handler at /events/32days will receive the following payload:
{ "id": "TBqDft2LrULaSxCzpMDXc6", "when": "2022-07-18T15:55:31.085Z", "build": "v202206001", "document": { "id": "Y9yJ4qDDMpHGmmYboWt4ZE", "customer": "MJvrmWjJ3zZe7pPWHWta7r" } }Delete Event
DELETE to /v1/event/{id}
https://api.anticipated.io/v1/event/{id}Deletes an event in the anticipated.io system. Events cannot be updated in the system, instead they should be removed and replaced with a new event. To delete an event send a DELETE request to the delete endpoint where {id} is the ID of the event. https://api.anticipated.io/v1/event/{id}
Response from the anticipated.io system will look like this for a delete operation:
{ "request": { "id": "HPUJTTKmvp3UYgyECjspUb" }, "context": { "user": null, "company": "6gtGBDj6jEre4xgFCAgrnj" }, "message": "", "now": "2022-06-17T15:55:31.125Z", "event": { "id": "TBqDft2LrULaSxCzpMDXc6", "company": "6gtGBDj6jEre4xgFCAgrnj", "type": "json", "when": "2022-07-18T15:55:31.085Z", "created": "2022-06-16T15:55:31.085Z", "details": { "document": { "id": "Y9yJ4qDDMpHGmmYboWt4ZE", "customer": "MJvrmWjJ3zZe7pPWHWta7r" }, "url": "https://myplatform.com/events/32days", "method": "post", "headers": [] }, "processed": false, "deleted": true } }Get Event
GET to /v1/event/{id}
https://api.anticipated.io/v1/event/{id}Retrieves an event from the anticipated.io system. To retrieve an event send a GET request to the delete endpoint where {id} is the ID of the event. https://api.anticipated.io/v1/event/{id}
Response from the anticipated.io system will look like this for a get operation:
{ "request": { "id": "HPUJTTKmvp3UYgyECjspUb" }, "context": { "user": null, "company": "6gtGBDj6jEre4xgFCAgrnj" }, "message": "", "now": "2022-06-17T15:55:31.125Z", "event": { "id": "TBqDft2LrULaSxCzpMDXc6", "company": "6gtGBDj6jEre4xgFCAgrnj", "type": "json", "when": "2022-07-18T15:55:31.085Z", "created": "2022-06-16T15:55:31.085Z", "details": { "document": { "id": "Y9yJ4qDDMpHGmmYboWt4ZE", "customer": "MJvrmWjJ3zZe7pPWHWta7r" }, "url": "https://myplatform.com/events/32days", "method": "post", "headers": [] }, "processed": false, "deleted": false } }
SDKs