Get orders and tracking data in one call

Hey all! New to this API, was wondering if there is a way to get orders and tracking numbers in a single call. We seem to be getting throttled pretty frequently, so instead of making calls order by order for a selected time range to the shipments object, was wondering if there is way to accomplish this. Seems like it would be a pretty common request. Thanks everyone!

Hi @jeffro25!
Unfortunately not on a single call, you will need to paginate through results.
But you could also use the Shipment Update webhook to get the data instead of fetching it

https://developer.shiphero.com/webhooks#shipment-update-webhook

And then you could also use the Shipments Query

https://developer.shiphero.com/examples-query/#shipments

But instead of using the order_id use the date filters:

query {
  shipments(date_from: "2021-06-01" date_to:"2021-06-02") {
    request_id
    complexity
    data {
      edges {
        node {
          id
          legacy_id
          order_id
          user_id
          warehouse_id
          pending_shipment_id
          address {
            name
            address1
            address2
            city
            state
            country
            zip
            phone
          }
          shipped_off_shiphero
          dropshipment
          created_date
          line_items(first: 10) {
            edges {
              node {
                line_item_id
                quantity
              }
            }
          }
          shipping_labels {
            id
            legacy_id
            account_id
            tracking_number
            carrier
            shipping_name
            shipping_method
            cost
            profile
            packing_slip
            warehouse
            insurance_amount
            carrier_account_id
            source
            created_date
          }
        }
      }
    }
  }
}

Thanks in advance!
Tom

@tomasw I figured it had to be separate calls. I will probably go the webhook route. Is there a way to iterate over line items on an order? I keep running into throttling when I don’t specify the first or last x amount of line items. I know how to iterate over the orders if you request more than the credits available, but I don’t really see a way of iterating over line items on an order. Not a huge deal, but curios in case I need to in the future. Thanks Tomas!

@tomasw the other reason I can’t really use the shipments query is because I am looking for shipments on orders for a specific store, which is why I was hoping to be able to lump these together so I could filter by store on the orders query and get only shipments from those specific orders.

Hi @jeffro25
My apologies for the delayed response about this!

So you would like to be able to filter shipments for a specific Store? Or maybe Customers?

Absolutely! this should be similar to other queries: GraphQL Primer – Developer Resources | ShipHero

This case would look something like this:

  • Example order is ID: 195249449 and has 3 Line Items. I will be fetching them by 2 using first:2
query {
  order (id:"195249449") {
    request_id
    complexity
    data {
      line_items(first:2) {
        pageInfo {
          hasNextPage
          endCursor
        }
        edges {
          cursor
          node {
            sku
            quantity
          }
        }
      }
    }
  }
}

I get this in response:

{
  "data": {
    "order": {
      "request_id": "60d1d5609e9372601ec15bf9",
      "complexity": 3,
      "data": {
        "line_items": {
          "pageInfo": {
            "hasNextPage": true,
            "endCursor": "YXJyYXljb25uZWN0aW9uOjE="
          },
          "edges": [
            {
              "cursor": "YXJyYXljb25uZWN0aW9uOjA=",
              "node": {
                "sku": "1122334459",
                "quantity": 1
              }
            },
            {
              "cursor": "YXJyYXljb25uZWN0aW9uOjE=",
              "node": {
                "sku": "1122334463",
                "quantity": 1
              }
            }
          ]
        }
      }
    }
  }
}

And it has: "hasNextPage": true, which means it has the next page of results, and the endCursor is YXJyYXljb25uZWN0aW9uOjE=

So in order to get the next set of results I will get the results after that cursor. The next query would be:

query {
  order (id:"195249449") {
    request_id
    complexity
    data {
      line_items(first:2 after:"YXJyYXljb25uZWN0aW9uOjE=") {
        pageInfo {
          hasNextPage
          endCursor
        }
        edges {
          cursor
          node {
            sku
            quantity
          }
        }
      }
    }
  }
}

And the result I get is for the remaining line item:

{
  "data": {
    "order": {
      "request_id": "60d1d5d837ccb8a4bc9072ff",
      "complexity": 3,
      "data": {
        "line_items": {
          "pageInfo": {
            "hasNextPage": false,
            "endCursor": "YXJyYXljb25uZWN0aW9uOjI="
          },
          "edges": [
            {
              "cursor": "YXJyYXljb25uZWN0aW9uOjI=",
              "node": {
                "sku": "1122334961",
                "quantity": 3
              }
            }
          ]
        }
      }
    }
  }
}

Now it shows "hasNextPage": false, which means there are no more results to display after the one we got.

Let me know if that doesn’t help!.
Thanks again for the patience,
Tom