Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
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":{}}}}
Solved! Go to the solution
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...
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
Waiting for any positive response
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...
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).
Hey @Shreyadeshmukh
First things to rule out:
'X-Shopify-Access-Token': password
Let me know how you go.
Scott | Developer Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog
@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.
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
Please contact me on my email thanks
User | RANK |
---|---|
6 | |
5 | |
5 | |
4 | |
4 |