Writing Data
The Trackstar API enables you to write data into your end users’ connected accounts. You can create new entities POST
and update existing entities PUT
.
Request Body
Every write request requires a JSON body. The request body will differ depending on the type of write request you are making and the integeration you are writing to.
e.g. Creating orders in WMS A will have a different request body than creating orders in WMS B.
To make it easier to dynamically write into WMS, Trackstar provides a meta
endpoint that allows you to get the schema of the request body for a write request.
Meta Endpoint
There are two meta
endpoints that return request body schemas for creating resources. The first returns the schema for a given integration and method, and the second returns the schema for a given connection and method.
This is because some integrations have connection-specific custom fields.
The following is our recommended flow for making a successful write request:
- Call the integration + method
meta
endpoint, e.g.GET
/wms/inbound-shipments/meta/<integration_name>?method=POST
- This endpoint includes a
has_connection_specific_field
boolean, which indicates if hitting the connection-specificmeta
endpoint is required. - If
has_connection_specific_field
istrue
call the connection specific + methodmeta
endpoint, e.g.GET
/wms/inbound-shipments/meta?method=POST
withaccess_token=abc123
- Use these schemas to create a resource.
Meta Response
The top level of the connection-level meta
response is an object with three keys: schema
, definitions
, and $ref
. The more generic integration-level meta
endpoint will also include has_connection_specific_fields
, which indicates whether or not an access token is required to get the full schema.
Every definition has properties
, a list of elements called required
, and a type
(equal to object
).
This schema conforms to the JSON Schema Draft 07 specification. More information can be found there.
Benefits of Meta Endpoints
Instead of building customized write logic for every integration, /meta
allows you to:
- Dynamically generate the request body schema for a write request
- Automatically account for differences between integrations
- Autogenerate user interfaces for your end users to create and update entities
Example
The following example demonstrates how to take the response from the meta
endpoint and use it to create the request body for a write request.
Write Request Flow
- Call Meta endpoint(s) to get the schema of the request body.
- Generate a user interface (e.g. a form) based on the schema.
- On submit, serialize the form data into a JSON object.
- Call
POST wms/<object_type>
orPUT wms/<object_type>
with the JSON object as the request body.
Example UI Creation
The example React code below demonstrates how to use the meta endpoint to generate a form for creating an inbound-shipment.