Developer Resources > Examples
Inventory Snapshot
In this section, we will explore some examples of how we can use the Inventory snapshot.
Overview:
A snapshot is just an asynchronous job that iterates over all warehouses that satisfy the criteria (owned or associated with a 3PL relationship), then iterates over all products in each warehouse that meet the criteria and aggregates vendors+bins+lots for each product, and throws all of that info into a big map of products to vendors, warehouses, and lots for each in JSON format.
When it finishes, it can send an email or post to an endpoint. This email or webhook will contain a link to the exported JSON file, which will be available for download for 24 hours.
To get either of the above, you must pass the notification_email or post_url fields respectively. Please ensure you are passing a valid email and/or endpoint URL that accepts POST messages.
We also offer a data export option that may be better suited for your needs. Reach out to support for more information.
Examples of how the snapshot should look like are:
Important notice:
Requesting a full snapshot of all products from all warehouses is not recommended, and the request may not succeed for accounts with high SKU and warehouse counts.
To limit the size of the snapshot, use one of the following filters:
warehouse_id
to get results for a specific warehouse.customer_account_id
to receive only SKUs for a specific customer account if you trigger the snapshot as a 3PL account.has_inventory
to return only SKUs that have stock.updated_from
to retrieve only SKUs that have been updated since the specified date-time (in UTC).
Inventory generate snapshot Mutation:
In this example we will use the inventory_generate_snapshot
Mutation, that allows us to generate a snapshot:
mutation { inventory_generate_snapshot( data: { warehouse_id: "V2FyZWhvuXNlOjEjUzkw" notification_email: "test@shiphero.com" } ) { request_id complexity snapshot { snapshot_id job_user_id job_account_id warehouse_id customer_account_id notification_email email_error post_url post_error post_url_pre_check status error created_at enqueued_at updated_at snapshot_url snapshot_expiration } } }
And the response for it should be something like this:
{ "data": { "inventory_generate_snapshot": { "request_id": "5e70d213fa462c9432d1a383", "complexity": 30, "snapshot": { "snapshot_id": "5e70d213ec6c5e62d4bf7170", "job_user_id": "VXNlcjo5MTIz", "job_account_id": "QWNjb3VudDo2MzM0", "warehouse_id": "V2FyZWhvuXNlOjEjUzkw", "customer_account_id": null, "notification_email": "test@shiphero.com", "email_error": null, "post_url": null, "post_error": null, "post_url_pre_check": true, "status": "enqueued", "error": null, "created_at": "2020-03-17T13:35:15+00:00", "enqueued_at": "2020-03-17T13:35:15.815864+00:00", "updated_at": "2020-03-17T13:35:15+00:00", "snapshot_url": null, "snapshot_expiration": null } } } }
Inventory abort snapshot Mutation:
If you would like to abort a snapshot that is being generated, you can use the inventory_abort_snapshot
Mutation, that allows us to abort a specific snapshot, this is:
mutation { inventory_abort_snapshot( data: { snapshot_id: "5e94c048cec17923fcb7ec32", reason: "Wrong endpoint" } ) { request_id complexity snapshot { snapshot_id job_user_id job_account_id warehouse_id customer_account_id notification_email email_error post_url post_error post_url_pre_check status error created_at enqueued_at updated_at snapshot_url snapshot_expiration } } }
Notes:
- Snapshots can also be posted to a specific URL. In order to do this, you have to include two fields:
post_url:”https://testendpoint.net/”
post_url_pre_check:falseAs for post_url_pre_check, if false, a pre-check on the POST URL will not be performed. This eliminates immediate validation and feedback in the mutation response, before sending the request to the worker. Nonetheless, disabling this check can be useful if a one-time token is used to authenticate the endpoint.
Inventory snapshot Query
This query allows us to get the status for a specific snapshot
query { inventory_snapshot(snapshot_id: "5e94c048cec17923fcb7ec32") { request_id complexity snapshot { snapshot_id job_user_id job_account_id warehouse_id customer_account_id notification_email email_error post_url post_error post_url_pre_check status error created_at enqueued_at updated_at snapshot_url snapshot_expiration } } }
And the response should look something like this:
{ "data": { "inventory_snapshot": { "request_id": "5e94c1d95dd8b16bf28392a9", "complexity": 1, "snapshot": { "snapshot_id": "5e94c048cec17923fcb7ec32", "job_user_id": "VXNlcjo5MTIz", "job_account_id": "QWNjb3VudDozODAx", "warehouse_id": "V2FyZWhvdXNlOjgwNzU=", "customer_account_id": null, "notification_email": "test@shiphero.com", "email_error": null, "post_url": null, "post_error": null, "post_url_pre_check": true, "status": "success", "error": null, "created_at": "2020-04-13T19:40:56+00:00", "enqueued_at": "2020-04-13T19:40:56.912000+00:00", "updated_at": "2020-04-13T19:40:57+00:00", "snapshot_url": "https://shiphero-uploads.s3.amazonaws.com/inventory_snapshots/3801/8075/Any/b24278f6-7dbe-11ea-9903-0af9fd70a979.json", "snapshot_expiration": null } } } }
Inventory snapshots Query
This query allows us to get the status of all the snapshots for a specific warehouse or customer
query { inventory_snapshots(warehouse_id: "V2FyZWhvdXNlOjgwNzU=") { request_id complexity snapshots(first: 1) { edges { node { snapshot_id job_user_id job_account_id warehouse_id customer_account_id notification_email email_error post_url post_error post_url_pre_check status error created_at enqueued_at updated_at snapshot_url snapshot_expiration } } } } }
And the response should look something like this:
{ "data": { "inventory_snapshots": { "request_id": "5e94c0c401117d1e2b1a822c", "complexity": 11, "snapshots": { "edges": [ { "node": { "snapshot_id": "5e94c048cec17923fcb7ec32", "job_user_id": "VXNlcjo5MTIz", "job_account_id": "QWNjb3VudDozODAx", "warehouse_id": "V2FyZWhvdXNlOjgwNzU=", "customer_account_id": null, "notification_email": "test@shiphero.com", "email_error": null, "post_url": null, "post_error": null, "post_url_pre_check": true, "status": "success", "error": null, "created_at": "2020-04-13T19:40:56+00:00", "enqueued_at": "2020-04-13T19:40:56.912000+00:00", "updated_at": "2020-04-13T19:40:57+00:00", "snapshot_url": "https://shiphero-uploads.s3.amazonaws.com/inventory_snapshots/3801/8075/Any/b24278f6-7dbe-11ea-9903-0af9fd70a979.json", "snapshot_expiration": null } } ] } } } }