Adding old customers to shopify customers using API fails

prachi_oza
Tourist
7 1 0

Hi,

I am trying to use shopify admin apis to add customers to my shopify store and am unable to make it work so far. Below is the curl call that I am making and its response-

 

Request:

curl -v --location --request POST 'https://store.juniorfy-Access-Token: ****' --header 'Content-Type: application/json' --header 'Cookie: request_method=POST' --data-raw '{"customer":{"first_name":"Steve","last_name":"Lastnameson","email":"steve.lastnameson@example.com","phone":"+15142546011","verified_email":true,"addresses":[{"address1":"123 Oak St","city":"Ottawa","province":"ON","phone":"555-1212","zip":"123 ABC","last_name":"Lastnameson","first_name":"Mother","country":"CA"}]}}'

Response

{"errors":{"customer":"Required parameter missing or invalid"}}

somehow I am unable to add older customers using APIs and this example request if from the documentation itself, refer https://shopify.dev/docs/api/admin-rest/2023-01/resources/customer.

I think listing parameters Mandatory or optional should help users to adapt to the api.

Replies 5 (5)

SB_90
Shopify Partner
216 52 69

Hi @prachi_oza 

 

I've just sent this exact request and it's been successful.


Are you sending it to a store with the right scopes?

 

I'm presuming you can make other API calls fully authenticated?

 

Can you try sending it using say Node.js or some other method just to see if it's something in the curl request specifically causing the problem?

prachi_oza
Tourist
7 1 0

Hi,

 

- For scopes, I have enabled all of them.

- For authentication, I have ensured it is correct as I am able to successfully search customers or get counts via GET requests

- I have tried using postman to send the queries and all I get in response is 200 OK and a list of existing customers, but the new one does not get added.

I am not well quipped in Node.js, but can try python to do it.

prachi_oza
Tourist
7 1 0

What version of curl were you using when the request was successful for you?

prachi_oza
Tourist
7 1 0

Also, I have noticed that although curl gives me an error, postman or python, both give me a response code of 200 OK, and return the whole json of all the customers, excluding the one I just added. The customers count also does not increase, I get an empty response when I search this customer I am trying to add.

200 Ok should mean my call went through and the customer has been added, but why can't I see the customer in the list of customers or why the count doesn't change, I have no clue. I am fairly new to shopify, and these API's and I assumed it did not work given that I cannot see the customer. It may be my ignorance, but the documentation says I should expect a 201 OK with the post call. Please suggest.

 

I want to add my existing customers to shopify and get them to review our products.

ShopifyDevSup
Shopify Staff
1359 227 475

Hi prachi_oza,

 

The specific behaviour of getting a list of customers in return instead of creation of a new customer sounds like a currently known issue with some clients when performing API requests on a secondary .myshopify.com domain instead of the original one. In such cases some clients will respond to the redirect that happens by changing the request to a GET from a POST.

 

The potentially quick solution for that is to check in Settings > Domains in the store admin to see if there is another .myshopify.com domain present and if so to try use that one. 

 

Since this can be very store specific, if you're still having trouble and have a staff account on the store it's best to reach out to Support directly to help maintain privacy.

 

Thanks and hope you have a great day

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog