我正在开发 Shopify React Native 应用程序。我正在尝试使用我的应用创建新客户。它在 Postman 上运行良好,但不适用于我的应用程序。应用程序。我还在 shopify 上设置了我的私人应用程序并从那里获取所有必需的凭据。
我在这里发布我的代码。
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)
})
}
{
"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,gcp-us-central1",
"x-xss-protection": "1; 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": "DYNAMIC",
"alt-svc": "h3-27=\":443\"; 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": {}
}
}
}
这是我从邮递员那里得到的回复:
{
"customer": {
"id": 3028204847146,
"email": "testuser@example.com",
"accepts_marketing": false,
"created_at": "2020-06-14T15:59:02+05:30",
"updated_at": "2020-06-14T15:59:02+05:30",
"first_name": "test",
"last_name": "user",
"orders_count": 0,
"state": "disabled",
"total_spent": "0.00",
"last_order_id": null,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": "+15154346011",
"tags": "",
"last_order_name": null,
"currency": "INR",
"addresses": [
{
"id": 3226192674858,
"customer_id": 3028204847146,
"first_name": "test",
"last_name": "user",
"company": null,
"address1": "123 Oak St",
"address2": null,
"city": "Ottawa",
"province": "Ontario",
"country": "Canada",
"zip": "123 ABC",
"phone": "+15154346011",
"name": "test user",
"province_code": "ON",
"country_code": "CA",
"country_name": "Canada",
"default": true
}
],
"accepts_marketing_updated_at": "2020-06-14T15:59:02+05:30",
"marketing_opt_in_level": null,
"tax_exemptions": [],
"admin_graphql_api_id": "gid://shopify/Customer/3028204847146",
"default_address": {
"id": 3226192674858,
"customer_id": 3028204847146,
"first_name": "test",
"last_name": "user",
"company": null,
"address1": "123 Oak St",
"address2": null,
"city": "Ottawa",
"province": "Ontario",
"country": "Canada",
"zip": "123 ABC",
"phone": "+15154346011",
"name": "test user",
"province_code": "ON",
"country_code": "CA",
"country_name": "Canada",
"default": true
}
}
}