Developer Resources > Examples

Inventory Sync

 

In this section, we will explore some examples of how can you use Inventory Sync.

Note: For better readability, all of the available fields may not be included in our example queries. To navigate through the Schema and see all of the fields available, please check our Documentation section.

Overview:

In this section, we will explore some examples of how you can use the Inventory Sync feature to Sync inventory using a CSV file.

This new Feature resembles the one availabe on our Web App through Inventory Upload.

For these examples, we will follow this flow:

  1. Upload a CSV file using inventory_sync mutation
  2. Check all the inventory_sync_statuses by using a query
  3. Check a particular inventory_sync_status using a query
  4. Check all the rows of that batch with an inventory_sync_items_status query

Inventory sync Mutation:

In this example you will use the inventory_sync Mutation, that allows you to upload inventory:

mutation{
  inventory_sync(data:{
    url:"https://some-url.com/inv-sync.csv",
    warehouse_id:"V2FyZdfhens73hsA="
  }){
    request_id
    complexity
    sync_id
  }
}

And the response for it should be something like this:

{
  {
  "data": {
    "inventory_sync": {
      "request_id": "5d9624af8f00587f435deb37",
      "complexity": 0,
      "sync_id": "5d9624b054de070001fd315a"
    }
  }
}

Notes:

  • Fields that need to be on the CSV file are: #sku, quantity, action, reason and in case the account has Dynamic Slotting, location.
  • For Dymanic Slotting account, if you don’t include location it will be assigned to an unassigned bin.
  • All SKUs included must be existing SKUs and available on that specific warehouse.
  • CSV file also needs to be available for download without any type of credentials needed.
  • Only replace is supported foraction.
  • CSV file shouldn’t have over 3000 lines to achieve optimal processing performance.
  • For an example CSV file, please see:
    Static Slotting Accounts: Download File
    Dynamic Slotting Accounts: Download File

Inventory sync statuses Query

This query allows you to get the status from all the sync batches you have

query {
  inventory_sync_statuses {
    request_id
    complexity
    data(first:3) {
      edges {
        node {
          id
          url
          user_id
          account_id
          warehouse_id
          customer_account_id
          total_count
          status
          error
          created_at
          updated_at
        }
      }
    }
  }
}

And the response should look something like this:

{
  "data": {
    "inventory_sync_statuses": {
      "request_id": "5d9654d6d49dd410acb3f5644",
      "complexity": 11,
      "data": {
        "edges": [
          {
            "node": {
              "id": "5d9624b054de070001fd315",
              "url": "https://some-url.com/inv-sync.csv",
              "user_id": "VXNlcjo5MTIp",
              "account_id": "iWNjb3VudDozODA1",
              "warehouse_id": "V2FyZWh3eXNlOjQzNTA=",
              "total_count": 3,
              "status": "error",
              "error": "error in 3 out of 3 rows",
              "created_at": "2019-10-03T16:41:20+00:00",
              "updated_at": "2019-10-03T16:41:21+00:00"
            }
          },
          {
            "node": {
              "id": "5d95fc1754de070001fd30a",
              "url": "https://some-url2.com/inv-sync.csv",
              "user_id": "VXNlcjo5MTIp",
              "account_id": "iWNjb3VudDozODA1",
              "warehouse_id": "V2FyZWh3eXNlOjQzNTA=",
              "total_count": 178,
              "status": "error",
              "error": "error in 178 out of 178 rows",
              "created_at": "2019-10-03T13:48:07+00:00",
              "updated_at": "2019-10-03T13:48:14+00:00"
            }
          },
          {
            "node": {
              "id": "5d95f884f5189700012e690",
              "url": "https://some-url.com/inv-sync.csv",
              "user_id": "VXNlcjo5MTIp",
              "account_id": "QWNjb3VudDozODA1",
              "warehouse_id": "V2FyZWhvdXNlOjQzNTA=",
              "total_count": 3,
              "status": "error",
              "error": "error in 3 out of 3 rows",
              "created_at": "2019-10-03T13:32:52+00:00",
              "updated_at": "2019-10-03T13:32:59+00:00"
            }
          }
        ]
      }
    }

Inventory sync status Query

This query allows you to get the status of a specific sync batch

query{
  inventory_sync_status(id:"5d9624b054de070001fd3132"){
    request_id
    complexity
    data{
       id
    url
    user_id
    account_id
    warehouse_id
    customer_account_id
    total_count
    status
    error
    created_at
    updated_at
    }
  }
}

And the response should look something like this:

{
  {
  "data": {
    "inventory_sync_status": {
      "request_id": "5d9624b054de070001fd3132",
      "complexity": 1,
      "data": {
        "id": "5d9b6a3ba1361e00012268ea",
        "url": "https://some-url.com/inv-sync.csv",
        "user_id": "VXNlcjo5MTIz",
        "account_id": "QWNjb3VudDozODAx",
        "warehouse_id": "V2FyZWhvdXNlOjY1NDU=",
        "customer_account_id": null,
        "total_count": 5,
        "status": "success",
        "error": null,
        "created_at": "2019-10-07T16:39:23+00:00",
        "updated_at": "2019-10-07T16:39:24+00:00"
      }
    }
  }
}

Inventory sync items status Query

This query allows you to get status for every row inserted from a specific sync batch

query {
  inventory_sync_items_status(id: "5d9625ebd49dd410acb3f554") {
    request_id
    data {
      edges {
        node {
          id
          row
          sku
          quantity
          action
          reason
          location
          status
          error
          created_at
          updated_at
        }
      }
    }
  }
}

And the response should look something like this:

{
  "data": {
    "inventory_sync_items_status": {
      "request_id": "5d9b6adb2e9fef31169533f8",
      "complexity": 101,
      "data": {
        "edges": [
          {
            "node": {
              "id": "5d9b6a3ba1361e00012268e8",
              "row": 1,
              "sku": "45933041",
              "quantity": 10,
              "action": "change",
              "reason": "Reason for changing inventory",
              "location": null,
              "status": "success",
              "error": null,
              "created_at": "2019-10-07T16:39:23+00:00",
              "updated_at": "2019-10-07T16:39:24+00:00"
            }
          },
          {
            "node": {
              "id": "5d9b6a3ba1361e00012268e8",
              "row": 2,
              "sku": "46401204",
              "quantity": 10,
              "action": "change",
              "reason": "Reason for changing inventory",
              "location": null,
              "status": "success",
              "error": null,
              "created_at": "2019-10-07T16:39:23+00:00",
              "updated_at": "2019-10-07T16:39:24+00:00"
            }
          },
          {
            "node": {
              "id": "5d9b6a3ba1361e00012268e8",
              "row": 3,
              "sku": "49071335",
              "quantity": 10,
              "action": "change",
              "reason": "Reason for changing inventory",
              "location": null,
              "status": "success",
              "error": null,
              "created_at": "2019-10-07T16:39:23+00:00",
              "updated_at": "2019-10-07T16:39:24+00:00"
            }
          },
          {
            "node": {
              "id": "5d9b6a3ba1361e00012268e8",
              "row": 4,
              "sku": "47028683",
              "quantity": 10,
              "action": "change",
              "reason": "Reason for changing inventory",
              "location": null,
              "status": "success",
              "error": null,
              "created_at": "2019-10-07T16:39:23+00:00",
              "updated_at": "2019-10-07T16:39:24+00:00"
            }
          },
          {
            "node": {
              "id": "5d9b6a3ba1361e00012268e8",
              "row": 5,
              "sku": "48061840",
              "quantity": 10,
              "action": "change",
              "reason": "Reason for changing inventory",
              "location": null,
              "status": "success",
              "error": null,
              "created_at": "2019-10-07T16:39:23+00:00",
              "updated_at": "2019-10-07T16:39:24+00:00"
            }
          }
        ]
      }
    }
  }
}

Inventory sync abort Mutation

This mutation allows you to abort a specific sync batch that was uploaded. Aborting a sync batch should be done before the batch is changed to a success status, and will not revert the lines already processed from the CSV file.

mutation {
  inventory_sync_abort(
    data: { sync_id: "5e4dac71b50fb5475c7b00d4", reason: "Wrong File" }
  ) {
    request_id
    complexity
    sync {
      id
      url
      user_id
      account_id
      warehouse_id
      customer_account_id
      total_count
      status
      error
      created_at
      updated_at
      success_count
      error_count
      finished_count
    }
  }
}