Unable to create new customer through api

aecomtech
Tourist
9 0 2

Hi, I am using shopify api for creating new customer.


API is : admin/api/2020-04/customers.json.

Body json:

"customer": {
"first_name":null,
"last_name":null,
"email":"emailaddress@dmn.com"
}


Its returning list of existing customers instead of creating new customer.

 

Anyone please help...

0 Likes
aecomtech
Tourist
9 0 2
 const postData = {
customer:{
"first_name":null,
"last_name":null,
"email":"emailaddr@dmn.com"
}
}

const final_results = await fetch("https://" +ctx.params.domain + "/admin/api/2020-04/customers.json" , {
       headers: {
         'Content-Type': 'application/json',
         "X-Shopify-Access-Token": token,
       },
       method: 'POST',
       body: JSON.stringify(postData)
     })

It returns the list of exsisting customers, but the new email is not added to the list. I'm pretty sure im using POST method instead of GET.

0 Likes
michael-helium
Shopify Expert
228 1 117

Hi @aecomtech,

You should check out how the Customer Fields app handles this... might be a valuable alternative for you. See Customer Fields Developer Documentation.

Michael | Business Development @ Helium
Helium builds apps that merchants depend on:
- Customer Fields ✪ 4.9/5 (242 reviews)
- Meteor Mega Menu ✪ 4.7/5 (203 reviews)
aecomtech
Tourist
9 0 2

Thanks, but im very curious why the api didn't return the proper result. This api is working fine on development store but not on production. Also worked last week, we just found its not working prperly from yesterday.

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 227

Looking at the API documentation (https://shopify.dev/docs/admin-api/rest/reference/customers/customer?api[version]=2020-04#create-202...) it should be pretty straightforward. Have to you tried to creatr a customer with non-null first and last name fields defined?

0 Likes
aecomtech
Tourist
9 0 2

Yes, these are what i tried:

{
  customer: {
    first_name: 'First',
    last_name: 'Last',
    email: 'raleamil@gmail.com'
  }
}

It returns 50 existing cutomer list, not the return mentioned in api document.

I also tried this and returns the same thing.

{
  customer: {
    email: 'raleamil@gmail.com'
  }
}

I tried customerCreate mutation as well, it return 'not found', its like im using a GET but not POST. But im sure im using POST method.

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 227

First of all I'd suggest just trying Postman for issuing these test API calls. It should be easy to try out different calls and easily modify things if need be. When I just did this it worked out fine. Results pasted below for the API request/response pair. Keep in mind that you need to properly format your JSON request body. In this case, the properties and their values need to be enclosed on double quotes :)

 

POST https://{my_shop}.myshopify.com/admin/api/2020-04/customers.json HTTP/1.1
Content-Type: application/json
Authorization: Basic {my_access_token}
User-Agent: PostmanRuntime/7.25.0
Accept: */*
Host: {my_shop}.myshopify.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 115

{
  "customer": {
    "first_name": "First",
    "last_name": "Last",
    "email": "raleamil@gmail.com"
  }
}
HTTP/1.1 201 Created
Date: Tue, 16 Jun 2020 14:10:25 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=d1371222b1ff3648bc00bbcc620eb310d1592316625; expires=Thu, 16-Jul-20 14:10:25 GMT; path=/; domain=.myshopify.com; HttpOnly; SameSite=Lax
X-Sorting-Hat-PodId: 161
X-Sorting-Hat-ShopId: 3036253
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 3036253
X-ShardId: 161
X-Stats-UserId: 
X-Stats-ApiClientId: 309925
X-Stats-ApiPermissionId: 8304915
X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Shopify-Shop-Api-Call-Limit: 1/40
X-Shopify-API-Version: 2020-04
Location: https://{my_shop}.myshopify.com/admin/customers/3682110374050
Strict-Transport-Security: max-age=7889238
X-Shopify-Stage: production
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://cdn.shopifycdn.net https://cdn.shopify.cn https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fcustomers&source%5Bsection%5D=admin_api&source%5Buuid%5D=b78f858c-6647-4d87-b552-73d5c2c704a3
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fcustomers&source%5Bsection%5D=admin_api&source%5Buuid%5D=b78f858c-6647-4d87-b552-73d5c2c704a3
X-Dc: gcp-us-central1,gcp-us-east1,gcp-us-east1
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
X-Request-ID: b78f858c-6647-4d87-b552-73d5c2c704a3
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
CF-Cache-Status: DYNAMIC
cf-request-id: 035f10997a0000e1c6810ab200000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 5a451d3bfc72e1c6-ORD
alt-svc: h3-27=":443"; ma=86400
Content-Length: 607

{"customer":{"id":3682110374050,"email":"raleamil@gmail.com","accepts_marketing":false,"created_at":"2020-06-16T14:10:25Z","updated_at":"2020-06-16T14:10:25Z","first_name":"First","last_name":"Last","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":null,"tags":"","last_order_name":null,"currency":"USD","addresses":[],"accepts_marketing_updated_at":"2020-06-16T14:10:25Z","marketing_opt_in_level":null,"tax_exemptions":[],"admin_graphql_api_id":"gid:\/\/shopify\/Customer\/3682110374050"}}
0 Likes