Using the graphql api to fetch customer names and shipping city and zip

Using the graphql api to fetch customer names and shipping city and zip

dogowner
Shopify Partner
58 5 8

I'm trying to generate a picking list from an external inventory system by syncing orders placed with the external system.  The admin or staff then will open up picking lists from my app using appbridge and print them.

 

The graphql restrictions seem pretty high so I store as many identifiers as I can when I bulk import the orders into my external system but I didn't want to copy a bunch of customer information so I only store the IDS.  For the picking list I need to show the customer name and the customer shipping city, state and zip.   I have stored the order GQL id, customer GQL id, shipping GQL id.  I can fetch the customers by putting together a long list of single customer requests into one big request but how can I query the shipping address?  I see a MailingAddress object but is there an easier way to do all this?

 

My current psuedo code looks like this:

 

  • fetch imported orders from my database
  • gather up shopify customer ids from fetched orders
  • query them all from shopify to get the displayName and index by customer id (WORKING BUT CUMBERSOME)
  • gather up shopify shipping address ids from fetched orders
  • query them all from shopify to get city, state, zipcode and index by shipping address id (NOT WORKING)
  • convert orders to json, injected details from graphql api as needed
  • return to app running in appbridge and display

 

 

 

 

Replies 3 (3)

dogowner
Shopify Partner
58 5 8

I forgot the name of it but I'm using Aliases to fetch the customers.  I have only tested up to 3 at a time but eventually it will be around 30 or 40 at a time.  I'm not sure graphql will support that but that was my plan.  Will that work in parallel to some sort of MailingAddress query ?

dogowner
Shopify Partner
58 5 8

My customer query looks like this:

 

{ customer0: customer(id: "gid://shopify/Customer/REDACTEDID0") { id, displayName }
customer1: customer(id: "gid://shopify/Customer/REDACTEDID1") { id, displayName }
customer2: customer(id: "gid://shopify/Customer/REDACTEDID2") { id, displayName } }

Then I unpack it based on the suffix index after "customer".

 

Would I try to use an order query but then just fetch the address nested inside the order?

dogowner
Shopify Partner
58 5 8

This is working but I was hoping there was a better way:

 

{ order0: order(id: "gid://shopify/Order/REDACTEDID0") { id, shippingAddress { id, city, zip } }
order1: order(id: "gid://shopify/Order/REDACTEDID1") { id, shippingAddress { id, city, zip } }
order2: order(id: "gid://shopify/Order/REDACTEDID2") { id, shippingAddress { id, city, zip } } }