Hello,
I’m trying to get the full phone number from a shipping address using GraphQL API.
I have an example of an address with a phone number like “123456789” with no country prefix via API. I was expecting “+XX 123456789”.
At first, I thought about using the address country code to guess it, but when creating an address, a customer can type an address in a country and choose another country for the phone number. I did not find any way to get the country for the phone number with the API.
Has anyone managed to get the full phone number in all cases ?
Thanks
The phone number should be the full one entered at checkout.
What does your checkout look like for phone number entry? Have you done anything custom here?
Hello @JordanFinners
thanks for your reply.
As far as I know, there is nothing custom there.
I took a look at the settings in the admin but didn’t find anything.
And I must say this does not happen all the time.
Here is what it looks like for the customers :
As soon as you start typing a few numbers for the phone, the flag icon appears and you can change it. The UI then looks like the edit :
More info :
in the admin order page, for the order with the address without the phone prefix in the API : the shipping address block shows the full phone value.
But next to the shipping address, there is a “copy address” icon. When I click on it and paste the text, the phone prefix is not there.
Thing is… I do not know if the admin adds the prefix based on the address country (which would be an error) or if the phone country is stored but not available via the API.
I did not manage to reproduce the case myself. All data I have come from the production environment and I cannot play around with it.
When you view the order in Shopify Admin, you can add .json
to the end of the URL and it will show you a version of the data but in JSON format, so you’ll be able to see if the prefix is there.
You can also create a Shopify Dev Store for you to test this out Dev stores
Not there, sadly :
"shipping_address": {
"first_name": "XXXXX",
"address1": "XXXXXX 62",
"phone": "6605XXXXX",
"city": "Sant Miquel de Balenyà",
"zip": "08554",
"province": "Barcelona",
"country": "Spain",
"last_name": "XXXXXXXX",
"address2": null,
"company": null,
"latitude": 41.XXXXX,
"longitude": 2.XXXXXX,
"name": "XXXXX",
"country_code": "ES",
"province_code": "B"
},
I searched for “34” (the phone prefix for Spain) in the whole json, but nothing useful (ids or datetimes).
Then, I searched for "es"
and there is only the country code for the 2 addresses of the order + the customer default address.
Maybe this is a data that is not available at all
Hi,
I think you need to check the settings of the store, if there is something modifying the data, or any checkout apps or extensions.
I’ve just tried this on my own test store. Making the shipping phone number optional, using a temporary free number as an example
You can see it generates the flag and country code at the start.
In my order details it then has the correct phone number
"shipping_address": {
"first_name": "Bob",
"address1": "Bob",
"phone": "+34660099515",
"country": "United Kingdom",
"last_name": "Bob",
"address2": "Bob",
"company": null
And it shows correctly in the order details
Hi,
the weird thing is that it works most of the time, but as I said previously, there are some orders having the “raw” phone number.
When I try it myself, it works as intended too.
We’ll use a workaround.
Thanks a lot for your time !