Get order by legacy id

i need graph query for get order by legacy_id can you please provide me query for that.

HI @madhupatel!
You can use the order query and pass the legacy_id as id.
For example, if the legacy_id was 117902188, the query would be something like:

query {
  order(id: "117902188") {
    request_id
    complexity
    data {
      id
      legacy_id
      order_number
      shop_name
      fulfillment_status
      order_date
      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
      }
    }
  }
} 

You can also check for the id of that order using the uuid query, for example:

query {
  uuid(legacy_id: 117902188, entity: Order) {
    request_id
    complexity
    data {
      legacy_id
      id
    }
  }
}

hello team i need graph ql query for filter my order based on their tags .can you please share query for it.thanks in advance.

1 Like

Is there a way to get order details based on the order number instead of either of the IDs? We have an automation rule in ShipHero that sends us an email when an order is placed, and the only information it sends is the order number (which seems to be hard-coded in the Email action - I donā€™t see a way to get the email to include any more info).

I tried using the uuid query shown above, like this:

{"query":"query { uuid(order_number: 407, entity: Order) { request_id complexity data { legacy_id id order_number } } }"}

But it didnā€™t like the fact that I passed it an order number instead of an ID:

Exception in Task: Unhandled errors
{"errors":[{"message":"Unknown argument \"order_number\" on field \"uuid\" of type \"Query\".","locations":[{"line":1,"column":16}]},{"message":"Cannot query field \"order_number\" on type \"LegacyId\".","locations":[{"line":1,"column":124}]},{"message":"Field \"uuid\" argument \"legacy_id\" of type \"Int!\" is required but not provided.","locations":[{"line":1,"column":11}]}]}Error getting HTTP response: The remote server returned an error: (400) Bad Request.

Hi @jrtwynam

You could use the orders query, filter by order number and get the first result, this is for example:

query {
  orders(order_number: "MO801") {
    request_id
    complexity
    data(first: 1) {
      edges {
        node {
          id
          legacy_id
          order_number
          shop_name
          fulfillment_status
          order_date
          email
          profile
        }
      }
    }
  }
}

And as for the Error, it looks like the same we are discussing on Issue updating products
But the UUID will only work to make the request using the legacy_id, which is the id of the order on ShipHero and it wonā€™t work with the order number.
Let me know if that doesnā€™t work for you,
Thanks!

I just tried that, with the only change being to the order number in the criteria (and removing the newlines). It still gave me a bad request error.

I got something working where it runs the Orders query based on the order_number, which pulls back the legacy ID. I then use that ID in the Order query to pull back the order details. What Iā€™m wondering is how to tell what warehouse the order is allocated to. We have one that is allocated to our Primary warehouse (based on looking in the web UI at the order), but I donā€™t see anything in the resulting JSON from the Order query that tells me that.

Hi @tomasw,

Hereā€™s the JSON request for the order details:

query {
  order(id: "<enter order ID here>") {
    request_id
    complexity
    data {
      id
      legacy_id
      order_number
      shop_name
      fulfillment_status
      order_date
      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
      }
    }
  }
}

Hereā€™s the JSON that came back from the above request. I donā€™t see anything that tells me which warehouse(s) the order was allocated to. Ideally, an order should be entirely allocated to a single warehouse, but we came across a situation a few days ago where an order was partially allocated to both of our warehouses. In that situation, Iā€™d need to know where each order line is allocated.

{
  "data": {
    "order": {
      "request_id": "5e9dcfe6459b5d25d5e268be",
      "complexity": 3,
      "data": {
        "id": "T3JkZXI6MTIzMzY2Njcw",
        "legacy_id": 123366670,
        "order_number": "414",
        "shop_name": "<snip>",
        "fulfillment_status": "pending",
        "order_date": "2020-04-20T12:00:45-04:00",
        "profile": "default",
        "required_ship_date": "2020-04-21T20:00:00-04:00",
        "shipping_lines": {
          "carrier": "purolator",
          "method": "PurolatorGroundUS",
          "price": null
        },
        "shipping_address": {
          "first_name": "<snip>",
          "last_name": null,
          "address1": "<snip>",
          "address2": null,
          "city": "<snip>",
          "state": "<snip>",
          "state_code": null,
          "zip": "<snip>",
          "country": "US"
        },
        "tags": null,
        "line_items": {
          "edges": [
            {
              "node": {
                "id": "TGluZUl0ZW06MzYyNDY0ODY0",
                "sku": "70824420-FEL-10424-CS9284",
                "quantity": 1,
                "product_name": "Engine Conversion Gasket Set-VIN: B, CNG Fel-Pro CS 9284",
                "fulfillment_status": "pending",
                "quantity_allocated": 1,
                "backorder_quantity": 0,
                "barcode": null
              },
              "cursor": "YXJyYXljb25uZWN0aW9uOjA="
            }
          ]
        },
        "shipments": [],
        "returns": []
      }
    }
  }
}

I tried adding something like this to the request JSON:

query {
  order(id: "{JOB(Active|Variable|Legacy Order ID)}") {
    request_id
    complexity
    data {
      id
      legacy_id
      order_number
      shop_name
      fulfillment_status
      order_date
      profile
      required_ship_date
			*account {*
  •   			data {*
    
  •   				warehouses  {*
    
  •   					id*
    
  •   					legacy_id*
    
  •   					identifier*
    
  •   				}*
    
  •   			}*
    
  •   		}*
        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
        }
      }
    }
    
    }

But that request failed.

I figured it out. Although I havenā€™t found an all-inclusive list of the fields available to pull back in a query, I did find that Altair would suggest fields if you start typing. In my case, what I wanted was ā€œwarehouseā€:

1 Like

@tomasw, I thought I had figured it out, but itā€™s not returning the right data. It does return the order details, and the warehouse field ā€œworksā€ in the sense that it doesnā€™t give an error and does return a warehouse, but itā€™s not returning the warehouse that the order is allocated to. Hereā€™s the JSON returned by the order query:

  {
  "data": {
    "order": {
      "request_id": "5ea7a25b66ff0261dc78dcf4",
      "complexity": 101,
      "data": {
        "id": "T3JkZXI6MTI0NTEyOTI3",
        "legacy_id": 124512927,
        "order_number": "425",
        "shop_name": "<snip>",
        "fulfillment_status": "pending",
        "order_date": "2020-04-27T23:03:52-04:00",
        "profile": "default",
        "required_ship_date": "2020-04-28T20:00:00-04:00",
        "shipping_lines": {
          "carrier": "purolator",
          "method": "PurolatorGroundUS",
          "price": null
        },
        "shipping_address": {
          "first_name": "<snip>",
          "last_name": null,
          "address1": "<snip>",
          "address2": null,
          "city": "<snip>",
          "state": "<snip>",
          "state_code": null,
          "zip": "<snip>",
          "country": "US"
        },
        "tags": null,
        "line_items": {
          "edges": [
            {
              "node": {
                "id": "TGluZUl0ZW06MzY0ODc1MzQ1",
                "sku": "75922791-AIR-15222-57398",
                "quantity": 1,
                "product_name": "Suspension Leveling Kit-FX4 Rear Air Lift 57398",
                "fulfillment_status": "pending",
                "quantity_allocated": 1,
                "backorder_quantity": 0,
                "barcode": null,
                "locked_to_warehouse_id": null,
                "warehouse": "Primary"
              },
              "cursor": "YXJyYXljb25uZWN0aW9uOjA="
            }
          ]
        },
        "shipments": [],
        "returns": []
      }
    }
  }
}

That data clearly says itā€™s warehouse ā€œPrimaryā€, but the ShipHero web UI clearly shows itā€™s not:

Any ideas?

Thanks.

Hi @jrtwynam
I just wanted to let you know that this is been looked at right now, Iā€™ll try to provide a better insight as soon as possible.
I appreciate your patience on this!
Tom

@tomasw Iā€™ve noticed this as well so Iā€™m glad itā€™s being looked into.

Nearly all of our line items are show ā€œPrimaryā€ as the warehouse theyā€™re assigned to, even though many of them are actually set to ā€œShipHero will assignā€ and theyā€™re currently allocated to our second warehouse.

One line item I see in the data we sync from the GraphQL API does show that itā€™s assigned to our second warehouse, and when I look at that order in the dashboard I can see that the line item is locked to that second warehouse.

My hunch is that the API is returning which warehouse the line item is locked to, and if itā€™s not locked to a specific warehouse than it returns ā€œPrimaryā€, even if itā€™s currently allocated elsewhere.

Thank you!

-Sid

1 Like

Hi @jrtwynam @originsid
I got to reproduce this and already submitted a ticket for this to be looked at.
I do believe it should be showing the warehouse where is allocated to, but I might be missing something here.
I will let you know as soon as I get a response on this.
Thanks!

Hi,

Iā€™m just wondering if thereā€™s any update to this. Iā€™m still getting what appears to be incorrect data from the API regarding the warehouse.

Thanks.

Hi @jrtwynam
I apologize for the delay with this, I just raised priority so we can have a response about this.
I will provide an update as soon as this gets assigned.
Thanks again for your patience with this
Tom

hey @tomasw iā€™m facing issue when iā€™m creating order via graphql api .iā€™m getting error product with sku ā€˜zz_freight-small shpmtā€™ does not exist.
but when i try same details with rest api itā€™s not giving me any error and itā€™s successfully created.

Hi @madhupatel
Do you have the request_id of when you get that error?
Thanks in advance!,
Tom

[request_id] => 5ed4ef858250959ecad4e520
this is my request id.

Hi @madhupatel
Thanks for the info!
Right, that is because those SKUs donā€™t exist in the account, so It wont let you create order for non-existing SKUs
You will need to create those products on your account to be able to create an order with those products on it
Let me know if I could explain better or if there is anything else I could help you with
Thanks again!
Tom