Shopify create customer api is working on postman but not on react native app

Solved
Highlighted
Tourist
6 0 1

I am working on a Shopify React Native app. I am trying to create a new customer with my app. It is working fine on Postman but not working with my app.
app.
I have also setup my private app on shopify and get all the required credentials from there.

I am posting my code here.



let requestdata =
{
method: 'POST',
headers:
{
'Authorization':'Basic ' + base64.encode('apikey' + ":" +
'password'),
'Accept': 'application/json',
'Content-Type': 'application/json',

},

body: JSON.stringify({
"customer": {
"first_name": "test",
"last_name": "user",
"email": "testuser@example.com",
"phone": "+15154346011",
"verified_email": true,
"addresses": [
{
"address1": "123 Oak St",
"city": "Ottawa",
"province": "ON",
"phone": "+15154346011",
"zip": "123 ABC",
"last_name": "user",
"first_name": "test",
"country": "CA"
}
]
}}),

};

fetch('https://apikey:password@domainname/admin/api/2020-
04/customers.json', requestdata)
.then(res => {

console.log("resoponse",JSON.stringify(res))

this.setState({
data:res
})


}).catch((err)=>{
console.log(err)
})

}

Here is the response i am getting



{"type":"default","status":200,"ok":true,"headers":{"map":{"referrer-policy":"origin-when-cross-origin","cache-control":"no-cache, no-store","x-request-id":"fe78c2cb-1f8e-4cbc-815b-7a9aef11145e","cf-request-id":"0344067c9e00000f82b3286200000001","set-cookie":"_y=5de13f45-35f4-46a9-92f2-502b08a7ab8e; Expires=Fri, 11-Jun-21 08:09:37 GMT; Path=/, request_method=; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 GMT, _shopify_y=5de13f45-35f4-46a9-92f2-502b08a7ab8e; Expires=Fri, 11-Jun-21 08:09:37 GMT; Path=/","x-shardid":"41","x-shopify-login-required":"true","expect-ct":"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"","x-dc":"gcp-us-east1,gcp-us-central1,g...; mode=block; report=/xss-report?
source%5Baction%5D=login&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fauth&source%5Bsection%5D=admin&source%5Buuid%5D=fe78c2cb-1f8e-4cbc-815b-7a9aef11145e","x-sorting-hat-podid":"41","content-type":"text/html; charset=utf-8","x-frame-options":"DENY","x-download-options":"noopen","vary":"Accept-Encoding","date":"Thu, 11 Jun 2020 08:09:37 GMT","nel":"{\"report_to\":\"network-errors\",\"max_age\":2592000,\"failure_fraction\":0.01,\"success_fraction\":0.0001}, {\"report_to\":\"network-errors\",\"max_age\":2592000,\"failure_fraction\":0.01,\"success_fraction\":0.0001}","server":"cloudflare","x-content-type-options":"nosniff","x-shopify-stage":"production","report-to":"{\"group\":\"network-errors\",\"max_age\":2592000,\"endpoints\":[{\"url\":\"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify\"}]}, {\"group\":\"network-errors\",\"max_age\":2592000,\"endpoints\":
[{\"url\":\"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify\"}]}","cf-cache-status":"DYNA..."; ma=86400","x-shopid":"27371339818","shopify-auth-mechanisms":"password","content-language":"en","cf-ray":"5a19d9da9dab0f82-MXP","x-sorting-hat-shopid":"27371339818"}},"url":"https://apikey:password@domainname.myshopify.com/admin/auth/login","_bodyInit":{"_data":{"size":1323,"offset":0,"blobId":"0e0582a6-41ee-4cac-a1c4-b651149cc87f","__collector":{}}},"_bodyBlob":{"_data":{"size":1323,"offset":0,"blobId":"0e0582a6-41ee-4cac-a1c4-b651149cc87f","__collector":{}}}}

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1066 64 124

Hi there @Shreyadeshmukh!

Don here from Shopify.

I just wanted to let you know I had moved your topic here to the API forums as this is the best place to look for advice on these types of queries.

Though we're not able to provide API support ourselves here, these forums are moderated by our developer team and responded to by our developers and Partners.

Hopefully, the community will have some experience to draw upon to share with you here.

All the best!

 

Regards,

Don

Don | Social Care @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Highlighted
Tourist
6 0 1

Hi @Don ,
Thank you for forwarding my question to the API forum.

0 Likes
Highlighted
Tourist
6 0 1

Waiting for any positive response

 

0 Likes
Highlighted
Trailblazer
173 13 28

This is an accepted solution.

Have you tried it with using domainname.myshopify.com/admin... instead of apikey:password@domainname/admin... ? You are already authorizing with your credentials via the header.

 

But you might still run into a CORS error when you try to access Shopify API like this. If so, you will need to make a request to run your Shopify API code on the server side and then pass the result to the client side: https://community.shopify.com/c/Shopify-APIs-SDKs/Using-APIs-from-a-different-origin-domain/td-p/502...

0 Likes
Highlighted
Trailblazer
173 13 28

You might also be running into a cookies issue where it's directing you to a login page (Google and you'll see this is a common issue). 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

Hey @Shreyadeshmukh 


First things to rule out:

  • Replace Authorization header with:
'X-Shopify-Access-Token': password
  • As @policenauts1 suggested, remove 'apikey:password@' from the fetch URL

Let me know how you go.

Notice; Out of office, replies will be delayed until my return. Thanks!
Highlighted
Tourist
6 0 1

@policenauts1  Thank you for your response.

I was directly calling create customer api from my react native app(Frontend), I followed your suggestion and it worked for me, now i am calling create customer app using node js .

Thanks once again.

0 Likes
Highlighted
Tourist
6 0 1

@SBD_  Thank you for your response.

0 Likes
Highlighted
New Member
2 0 0

Hi Need Help For my store I am starting my own affiliate programme so I want to create the customer from my affiliate data to my shopping website.

please contact me who can helo me  Thanks

sunil9915640005@gmail.com

Please contact me on my email thanks 

0 Likes