Push API - nebulab/cangaroo GitHub Wiki
Cangaroo has just a single endpoint where you can push your data, based on
where Cangaroo::Engine is mounted, it will be reachable under the /endpoint
path. For example, if the Cangaroo::Engine is mounted under /cangaroo the
Push API path will be /cangaroo/endpoint.
When you push to the endpoint the HTTP Request must respect this conventions:
- It must be a
POSTrequest - It must be an
application/jsonrequest so you have to set theContent-Typeheader toapplication/json - The request must have the
X-Hub-StoreandX-Hub-Access-Tokenheaders set to a value that exists in theCangaroo::Connectionmodel (to learn more refer to theConnectiondocumentation below) - The request body must be a well formatted json.
The json body contains data that will be processed by Cangaroo, the following is an example of an order that will be processed on Cangaroo:
{
"orders": [
{
"id": "O154085346",
"status": "complete",
"email": "[email protected]"
}
]
}
The root objects of the json body must contain an array with the objects that
Cangaroo needs to process. The only required field for the objects contained
in the arrays will be the id key.
Push API also supports multiple objects so a request with the following body:
{
"orders":[
{
"id":"O154085346172",
"state":"cart"
},
{
"id":"O154085343224",
"state":"payed"
}
],
"shipments":[
{
"id":"S53454325",
"state":"shipped"
},
{
"id":"S53565543",
"state":"waiting"
}
]
}
will create 2 orders and 2 shipments.
When Cangaroo receives the request it responds with a 200(OK) HTTP status code and the response body will contain numbers of the objects in the payload, for example for the previous request the response will be:
{
"orders": 2,
"shipments": 2
}
if something goes wrong Cangaroo responds with an HTTP error code with an error message in the body, for example:
{
"error": "The property '#/orders/0' did not contain a required property of 'id' in schema"
}