What's your biggest current challenge? Have your say in Community Polls along the right column.

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

Solved

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

RobertM
Excursionist
20 0 4

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

Accepted Solution (1)
ishand1993
Shopify Partner
5 1 0

This is an accepted solution.

Ah it seems we were using an incorrect format, it should be query=name:<<order_name>>

I used the following endpoint and it worked - 

 

https://<<shop_name>>.myshopify.com/admin/api/2024-01/orders.json?query=name:<<order_name>>

 

This works with both %23 or straight up order name with #

Cheers!

View solution in original post

Replies 19 (19)

j_yates
Shopify Partner
3 0 0

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

RobertM
Excursionist
20 0 4

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
20 0 4

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
20 0 4

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
20 0 4

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
20 0 4

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
20 0 4

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

ishand1993
Shopify Partner
5 1 0

Question: Does it have to be in REST?
I found this looking for the similar functionality for draft orders (there is none) but tested orders endpoint using GraphQL with the # prefix and it works (it works even without the # prefix).

Pasting my query below, this goes in as payload in my api call -

let query = `{
    orders(first: 1, query: "name:#27638") {
      edges {
        node {
          name
          createdAt
          fullyPaid
        }
      }
    }
  }`;

 

RobertM
Excursionist
20 0 4

Yes, it has to be REST.  If the store is setup to use use anything other than the default prefix of # on an order it works perfectly.  i.e. order  US1234 works because we didn't use the default prefix of # but changed it to use US instead.  This is a problem with how Shopify deals with their default order prefix in a Store.  

Either their REST documentation is wrong, or the default order prefix #, is causing issues with JSON.  Either way, it is broken and Shopify needs to fix it.  At the very least they should stop using the default # prefix on orders.   Pick another prefix and it works.

ishand1993
Shopify Partner
5 1 0

This is an accepted solution.

Ah it seems we were using an incorrect format, it should be query=name:<<order_name>>

I used the following endpoint and it worked - 

 

https://<<shop_name>>.myshopify.com/admin/api/2024-01/orders.json?query=name:<<order_name>>

 

This works with both %23 or straight up order name with #

Cheers!

RobertM
Excursionist
20 0 4

That worked.  Thank you.  However, I had tried %23 previously.  The difference was how you constructed the end point. 

query=name:<<order_name>> is the answer, and I tested without the %23 as well.  It has been at least 9 months since I looked at this, but I don't recall seeing that option, so possibly the documentation has changed to add the query=name part.  In any event thank you for sharing this.

Zenoti
Shopify Partner
13 0 1

Hi @RobertM @ishand1993 , can you please guide me on how this works ?? I tried doing the same and it doesn't seem to work for me. Attaching the screenshot from postman, can you please guide me on what's wrong here, thanks.

Zenoti_2-1716290177007.png

 

 

RobertM
Excursionist
20 0 4

Hi Zenoti.  I wasn't using the 202401 version, but when I changed to that version, putting in the # sign failed.  Remove the # sign from the order number or change the # sign to be %23, and it will work.  I tested both at 202401.  Odd that it changed again from the version I was using.