-
Notifications
You must be signed in to change notification settings - Fork 18
Push API
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
POST
request - It must be an
application/json
request so you have to set theContent-Type
header toapplication/json
- The request must have the
X-Hub-Store
andX-Hub-Access-Token
headers set to a value that exists in theCangaroo::Connection
model (to learn more refer to theConnection
documentation 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"
}