Now that I’ve managed to get a working GraphQL task in my automation software, I’m trying to set up something that would get the inventory for all products from ShipHero. I found this query in the documentation’s examples:
query {
warehouse_products(warehouse_id: "V2FyZWhvdXNlOjgwNzU=") {
request_id
complexity
data(first: 2) {
edges {
node {
id
account_id
on_hand
inventory_bin
reserve_inventory
reorder_amount
reorder_level
custom
warehouse {
id
dynamic_slotting
profile
}
product {
id
name
sku
}
}
cursor
}
}
}
}
So where do I find the warehouse ID? We only have one warehouse in ShipHero, shown in the web UI as “Primary”, but I don’t see anywhere that displays the actual ID for that warehouse.
Similarly, I’ll be wanting to pull details for specific orders. We get an email every time an order comes in (set up in the automation rules in ShipHero), which contains the order number. There doesn’t seem to be a way to customize that part to send the order ID instead, and the API wouldn’t let me query by order number. It seems that the order ID is required for this query:
query {
order(id: "T3JkZXI6MTAwNTc0MjM1") {
request_id
complexity
data {
id
legacy_id
order_number
shop_name
fulfillment_status
order_date
ready_to_ship
profile
required_ship_date
shipping_lines {
carrier
method
price
}
shipping_address {
first_name
last_name
address1
address2
city
state
state_code
zip
country
}
tags
line_items(first: 2) {
edges {
node {
id
sku
quantity
product_name
fulfillment_status
quantity_allocated
backorder_quantity
barcode
}
cursor
}
}
shipments {
id
order_id
user_id
warehouse_id
address {
name
address1
address2
city
state
country
zip
}
shipped_off_shiphero
dropshipment
}
returns {
id
reason
status
}
}
}
}
To me, that query looks like it would read something like select * from orders where id = 'T3JkZXI6MTAwNTc0MjM1', if converted to standard SQL. So I thought why couldn’t I do select * from orders where order_number = '137' instead? Like this:
query {
order(order_number = "137") {
request_id
complexity
data { REST OF THE QUERY IS SNIPPED
Cool, that account query was exactly what I needed for the warehouse ID. Now I’m trying to get my pull of all our inventory to work. We have 2964 skus, and I’d like to pull all of them. It seems that the default is NOT to pull them all (i.e. I left the query as data { instead of data (first:100) {. So I tried setting it as data (first: 5000) {, but it told me I don’t have enough credits to run that. This raises a couple of questions:
If we only have 2964 skus, why would this query cost me 5001 credits? Regardless of how many records I set the limit as, the cost should be based on what was actually returned. So if I set the limit as 48534653098473465 records, the cost of this query should still be calculated based on 2964. Shouldn’t it?
Once we do have more than 5000 skus listed, how would I pull a complete list of them all in one shot? I’ll need to get the on hand quantity and the inventory bin; from there, I can pull those same values from our WMS and write some code to find the differences. I’ll then need to update ShipHero with whatever differences it found. How do others handle situations like this? It seems like the credit limit is set way too low.
So in the docs we do note that you cannot request more than 100 items per request. So even if you ask for 500, you will get 100. If you don’t specify a first parameter in connection fields, the max of 100 is assumed too, so beware that not sending first/last param will incur in a higher complexity.
When calculating the complexity it only takes into account your intention, not the actual result, so if you requested 100 but got 50, you are charged with 100 beforehand. You should always try to paginate the results instead of asking for many at once.
There have been some concern from users regarding the processing of inventory and the amount of credits required where there are lots of skus. We are considering this scenario but for now there are 5000 credits per hour, and you will have to accommodate your requests to that hourly limit.
Ok, so my next thought is to have my automation run every hour. That way, my credits will be renewed whenever it runs. I could loop through the API calls and pull say 2000 skus (i.e. pull 100 at a time, and run it 20 times). Then cross reference that list with our WMS to find differences; there should be enough credits left to update ShipHero even if all 2000 products are different (I’d hope).
The challenge with this is that I’d need a way to ensure that on the next run, it’s not just picking up the ones it checked on the previous run. I imagine I’d have to use the hasNextPage, startCursor and endCursor values somehow, so I’ll have to play around with that.
Since this original post, we’ve set up a second warehouse in ShipHero. Now, my issue is that I want to pull the warehouse ID only for a specific warehouse, but I don’t know how to add criteria to the account query. I tried this:
query {
account {
complexity
request_id
data {
id
legacy_id
email
username
status
is_3pl
warehouses {
id
legacy_id
identifier: "Primary"
}
}
}
}
But that gave me a “bad request” error. The original query works fine, except that it returns both warehouses, with the Primary warehouse in position [1] in the results, and the secondary warehouse in position [0]. I do have a way to pull out the ID in a specific position, but I don’t see anything that guarantees that the Primary warehouse will always be in position [1]. In fact, that’s counter-intuitive… it really should be in position [0] since it was the first warehouse we created and it’s the one that ships most of the orders (hence the name “Primary”). So what I’m looking for is a way to use that query, pass in the name “Primary” (i.e. what appears in the ShipHero Web UI), and have it return only the warehouse ID. Can I do that with a modification of this query? Maybe I just got the syntax wrong?
Hi @jrtwynam
I apologize for the delay in my response to this.
So the query should be something like:
query {
account {
complexity
request_id
data {
id
legacy_id
email
username
status
is_3pl
warehouses{
id
legacy_id
identifier
}
}
}
}
There is no need to include a filter in the warehouse, it will return all of the warehouses you have with its identifier and ID.
Let me know if this is not what you were looking for.
Thanks!
Thanks for the reply. The problem is that I don’t want it to return all warehouses - I only want it to return the data for our Primary warehouse, so I can pull out the ID for it. If it returns all warehouses, then I have to write some code to search through the JSON until it finds the Primary warehouse and then pull out the ID.
I should add that it’s not the end of the world if I do have to search through the results to find the one I’m looking for. Just a mild inconvenience - at least I do have a graphql query that’s working.
No problem at all!.
We currently don’t have that filter, and not sure if it will be build, but I will make a feature request for it to be added and let you know if it gets approved.
Thanks!
Tom