Skip to main content

Getting started with our API

An API request is composed of two main pieces of information:

  • Orders (with item information)
  • Bins

Below we demonstrate some minimal examples of how to send your first request to our API, and then incrementally add useful information to these.

Minimal example

Order

We now define an order with a single item with a width, height and depth of 1 (unit cube).

1{ 2 "id": "my_first_order", 3 "items": [ 4 { 5 "id": "item_1", 6 "width": 1, 7 "height": 1, 8 "depth": 1 9 } 10 ] 11}

Bin

Additionally, we provide a single bin with the same width, height and depth of the item of the order above.

1{ 2 "id": "bin_1", 3 "width": 1, 4 "height": 1, 5 "depth": 1 6}

Putting it together

Now we wrap both the order and the bin in a single JSON object and send it to our API using cURL. You will have to fill in your API key made in the web application, see our guide for that.

1curl -X 'POST' 'https://v4.api.optioryx.com/pack' -H 'x-api-key: <API_KEY>' -d '{ 2 "orders": [ 3 { 4 "id": "order_1", 5 "items": [ 6 { 7 "id": "item_1", 8 "width": 1, 9 "height": 1, 10 "depth": 1 11 } 12 ] 13 } 14 ], 15 "bins": [ 16 { 17 "id": "bin_1", 18 "width": 1, 19 "height": 1, 20 "depth": 1 21 } 22 ] 23}' 24

That's it! We just made our first API request to our API.

Creating an interactive visualisation of our result

From the API, we get back a response, which contains a response _id as one of the root-level attributes. This ID can be used to call another endpoint that generates an interactive visualisation of the packing result.

1curl -X 'GET' 'https://v4.api.optioryx.com/visualisation/interactive/<ID>/0/0?offline=false' -H 'x-api-key: <API_KEY>'

has to be replaced by the response _id and API key by your own key. In addition to the response ID, we also need to provide the order index and bin index we want to see. These are zero-based indices. The URL to which we have to send a GET request can also be found as the interactive_viz_url attribute of a bin in an order in the response.

We get the following visualisation back from our API: