Using REST API to get a single order by name when name contains a # prefix

RobertM
Excursionist
17 0 3

I'm having trouble retrieving single orders from a store. The name of the order is #6298. The # sign is the default prefix on the field "name" on the order. I have another store where the prefix of "name" is CA instead of the default. The order name is CA1801 which works.  Here are the details.
If I ask for the order CA1801 like this, it works and I get the order information returned properly.

"/admin/api/2023-07/orders.json?name=CA1801"

Note the order name is CA1801. I can do the same command using just 1801, leaving the CA off the beginning and I still get the order.  This has worked for years on testcompany1.

However, on another store the name on the order is #6298. When I substitute #6298 at the end for CA1801 above, it returns all the orders and not just the #6298 I asked for. If I just say that name=6298, it returns nothing.

It appears to be an issue with the # character that is stored in the name field.

"/admin/api/2023-07/orders.json?name=#6298"

I’m guessing you might have to do something special with putting the # sign in the cURL command, but I don’t know what it is. I can’t find any examples. I have tried these 5 and several other with no luck.  I have also tried using ?status=any&order_number=6298, but it also returns all orders.
/admin/api/2023-07/orders.json?name=#6298 << this returns all orders
/admin/api/2023-07/orders.json?name=6298 << this returns nothing

/admin/api/2023-07/orders.json?name=%236298 << this returns all the orders
/admin/api/2023-07/orders.json?name=”#6298” << this returns an error
/admin/api/2023-07/orders.json?name=”6298” << this returns an error

 

Thank you for taking a look, and any suggestions you may have.

Robert

Replies 13 (13)

j_yates
Shopify Partner
3 0 0

Try replacing the # with %23. This is the url encoding representation of "#".

RobertM
Excursionist
17 0 3

Thanks for replying, but in the third example I tried, I used the %23 in place of # and the results were exactly the same.  It returns everything.  To further clarify, I should be able to leave the # sign off and just use the number portion, but that returns nothing.  i.e. on one store both CA1801 and just 1801 bring back one order, but #6298 brings back all the orders and just 6298 brings back nothing.  It is inconsistent between the stores.  Weird.

j_yates
Shopify Partner
3 0 0

Ah sorry I overlooked that example! Have you tried using the orders API that uses the order id rather than the order name? Or is it important that you use the name for your search?

RobertM
Excursionist
17 0 3

Funny you should say that.  I did try to ask for order_number instead and I though it worked because it returned one order, but only if it was unfulfilled.  I tried it on an order that was fulfilled and it returned nothing.  Sometimes I need to look at order information again.  I then found some documentation that said I could say as well status=any, but then it returned all of the orders again and not the one I asked for.  It's frustrating because it works as the documentation says on one store, but not on the other.  There must be something not right on the store where the order has the # sign.  I thought it was the # sign, but maybe it is something else.  I cannot imagine what would be different between the stores though.

RobertM
Excursionist
17 0 3

One thing that I just found out that is different between the two stores is that the store that works perfectly is Shopify Plus, and the store that doesn't work is just Shopify.  Could that be the difference?  I would have thought that using GET to retrieve an order would be universal.  

j_yates
Shopify Partner
3 0 0

Yeah I'm not sure about that one, I don't believe the different tiers limits the API access, just the rate limit of requests.

RobertM
Excursionist
17 0 3

One thing that I just found out that is different between the two stores is that the store that works perfectly is Shopify Plus, and the store that doesn't work is just Shopify.  Could that be the difference?  I would have thought the using GET to retrieve an order would be universal.  

ChristianMacca
Tourist
4 0 0

FYI I've also experienced the same issue.  I use Shopify Basic.

 

Did you ever find a solution?

RobertM
Excursionist
17 0 3

No solution was ever provided by Shopify.  It is just broken.  Going forward I told my customers to stop using the default number sign # and start using something else for a prefix, like US or CDN etc.  It is crazy they would make the default prefix break the API. 

AthiraS
Tourist
4 0 2

I know it's late, but I've just encountered the issue and found a solution. Passing 'status' as a parameter works:

 

admin/api/2023-10/orders.json?name=1002&status=any

This is working for me.

RobertM
Excursionist
17 0 3

Thanks for the info Athira$, but I had already tried that and it still returns all the orders.  I tried it again now just in case something has changed.  The problem is that the default prefix in shopify is a #, so shopify stores the order number as #4325 as an example.  So if I use your example

admin/api/2023-10/orders.json?name=4325&status=any - it returns nothing. If I alter it to include the Shopify Prefix like this

admin/api/2023-10/orders.json?name=#4325&status=any - it returns all the orders.  If the prefix is anything other than the default # it work just fine.

The fix, as far as I can tell, is for users to change the default prefix to something else, or for Shopify to stop using the # as a prefix.

AthiraS
Tourist
4 0 2

I tried it in Postman and it works fine. Please find the screenshot attached.

 

postman.jpeg

cheers_emmanuel
Shopify Partner
1 0 0

This worked for me too. Thanks AthiraS