GET Customer Orders returning no results

Shopify Partner
6 0 0

Hi Shopify devs,

I'm trying to solve a problem a few other people have had: I want to get all the orders associated with a particular customer (by email, for example). I can get the customer ID/object by searching for the email so that's fine, but I'm getting stuck on getting the actual orders.

Looking at other threads and documentation I've tried the following calls

GET '/admin/orders.json?customer_id='.$cid;
GET '/admin/orders.json?query='.$cid;
GET "/admin/customers/$cid/orders.json";

Where $cid is the ID of a customer of course.

From what I've read that top line should be the one that works, but I'm getting no orders in the response. I've tried a few different customer IDs, and confirmed they actually have made orders too.

Has anyone else had issues with this end point? Can anyone spot anything I'm doing wrong? For reference, I'm working with a simple Shopify Interface class I wrote that works perfectly well with every other call I've ever needed. It's just this one call giving me grief!

Thanks in advance!

Pete.

0 Likes
Shopify Expert
2000 82 1452

Hey Pete,

The first line works for me using the same format noted here:
https://help.shopify.com/api/reference/customer#orders

eg:

/admin/orders.json?customer_id=1234567890

What is the actual response that you're getting back from the API?

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like
Shopify Partner
6 0 0

Hi Jason,

 


stdClass Object
(
    [header] => Array
        (
            [HTTP/1.1] => 200 OK
            [Server] => nginx
            [Date] => Tue, 22 Nov 2016 22:14:01 GMT
            [Content-Type] => application/json; charset=utf-8
            [Transfer-Encoding] => chunked
            [Connection] => keep-alive
            [Vary] => Accept-Encoding
            [X-Frame-Options] => DENY
            [X-ShopId] => 33333333
            [X-ShardId] => 4
            [X-Shopify-Shop-Api-Call-Limit] => 1/40
            [HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT] => 1/40
            [X-Stats-UserId] => 0
            [X-Stats-ApiClientId] => 1111111
            [X-Stats-ApiPermissionId] => 222222
            [X-XSS-Protection] => 1; mode=block; report=/xss-report/361fd896-ea01-38db-b11b-6bbe3c8738a8?source%5Baction%5D=index&source%5Bcontroller%5D=admin%2Forders&source%5Bsection%5D=admin
            [X-Request-Id] => 361fd896-ea01-38db-b11b-6bbe3c8738a8
            [P3P] => CP="NOI DSP COR NID ADMa OPTa OUR NOR"
            [X-Dc] => ash
            [X-Download-Options] => noopen
            [X-Permitted-Cross-Domain-Policies] => none
            [X-Content-Type-Options] => nosniff
        )

    [response] => stdClass Object
        (
            [orders] => Array
                (
                )

        )

)
That's the response I get, PPHP print_r on the decoded JSON. Empty orders Array. Have tried half a dozen different customer numbers from the given store. Seems to be a perfectly functional call, it's just not giving me the orders it should. I don't know. Same header response when I retrieve an order by the order ID or anything else so there's no obvious signs the call is wrong (to me anyway). Unfortunately I need to get this thing working in the next two days so I think I'm going to have to just maintain a local reference to order/customer IDs using webhooks. But still, would be helpful to figure this call out for longer term use. Cheers, Pete.
0 Likes
Shopify Partner
6 0 0

Well now I'm even more confused.

I posted a reply, with what I get back from the API, but I can't see that comment?!

For reference, the headers are exactly the same as any other successful API call, but the body is just an empty orders Array

[response] => stdClass Object
        (
            [orders] => Array
                (
                )

)

I was saying, I need to get this thing I'm building working in the next two days, so I'm going to have to just maintain a local reference for Customer/Order IDs and use webhooks to keep it up to date for now.

But would still love to figure out why it's not working

0 Likes
Shopify Partner
6 0 0

Update from 15 minutes later. Went to start adding this database and looping through existing orders and I've realised the GET /admin/orders.json call is actually the one giving me grief.

Seems to only give me recent/unfulfilled orders. The straight call should give me the last 50 orders as I understand it, but it's only giving me the last 2 (unfulfilled). And when I used the customer_id from one of those orders I was able to retrieve that order using /admin/orders.json?customer_id=###

So now I'm trying to figure out how to retrieve all orders through the API. Throwing on different parameters (like since_id=1000). Will post again if I figure anything out.

0 Likes
Shopify Partner
6 0 0

[RESOLVED]

OKAY

It seems my issue was in fact a simple one. I just need to pass status=any as a paramater on all calls to /admin/orders.json (including /admin/orders/count.json)

It is there in the API docs that the status defaults to open for those calls. Which is fair enough I suppose but a little confusing when you're expecting to just get ALL orders.

Considering this resolved for now. Always tentative but I think I'm all good. Hopefully this helps someone else.

Thanks all!

0 Likes
Shopify Expert
2000 13 313

Usually it helps to include a status. Like 'any'. You have be explicit when you request a general resource, like orders. If you have 200,000 closed ones, and 100,000 open ones, and 45,000 unfulfilled ones, it can make a wee bit of difference what you ask for right? 

So fulfillment status is also valuable, and potentially the since_id or created_at_min etc... 

And you can always have up to 250 at a time, over-riding the 50 limit.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Shopify Expert
132 0 5

note that 'any' status won't pull up archived orders

The eChics are here to help
0 Likes
Tourist
4 0 1

Hello! I may have a similar issue here
https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/get-customers-customer_id-orders-json-...

How do you pull up archived orders if "status=any" doesn't work?

For context, we are trying to pull up all of a customer's past orders when we call the API but only appear to be getting recent or unfulfilled orders. Thanks!

0 Likes
Highlighted
Shopify Expert
2000 13 313

Shopify no longer lets you pull up past orders without asking for special permission. You only get the most recent 60 days or something... by default now. 

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes