In this blog, We going to to create customer using REST API.

First we need to admin token to get customer info.
We can refer blog for generate admin token
https://www.magedad.com/magento-2-how-to-generate-admin-token-using-rest-api/

Rest API endpoint = https://domain.test/rest/V1/customers
Rest API endpoint for store(default is store code) = https://domain.test/rest/default/V1/customers
Method = POST
Content type = Content-Type:application/json
Header = Authorization: Bearer xxxx_admin_token_xxxx
Post Data =

JSON
{
  "customer": {
    "email": "jdoe3@example.com",
    "firstname": "Jane",
    "lastname": "Doe",
    "addresses": [
      {
        "defaultShipping": true,
        "defaultBilling": true,
        "firstname": "Jon",
        "lastname": "Doe",
        "region": {
          "regionCode": "NY",
          "region": "New York",
          "regionId": 43
        },
        "postcode": "10755",
        "street": [
          "123 Oak Ave"
        ],
        "city": "Purchase",
        "telephone": "512-555-1111",
        "countryId": "US"
      },
      {
        "defaultShipping": true,
        "defaultBilling": true,
        "firstname": "Jane",
        "lastname": "Doe",
        "region": {
          "regionCode": "NY",
          "region": "New York",
          "regionId": 43
        },
        "postcode": "10755",
        "street": [
          "123 Oak Ave"
        ],
        "city": "Purchase",
        "telephone": "512-555-1111",
        "countryId": "US"
      }
    ]
  },
  "password": "Password1"
}


Examples:
The following image shows a customer create by a REST client:


Here is simple php code for call API. This code is not recommended for Magento.

PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://domain.test/rest/V1/customers',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
  "customer": {
    "email": "jdoe3@example.com",
    "firstname": "Jane",
    "lastname": "Doe",
    "addresses": [
      {
        "defaultShipping": true,
        "defaultBilling": true,
        "firstname": "Jon",
        "lastname": "Doe",
        "region": {
          "regionCode": "NY",
          "region": "New York",
          "regionId": 43
        },
        "postcode": "10755",
        "street": [
          "123 Oak Ave"
        ],
        "city": "Purchase",
        "telephone": "512-555-1111",
        "countryId": "US"
      },
      {
        "defaultShipping": true,
        "defaultBilling": true,
        "firstname": "Jane",
        "lastname": "Doe",
        "region": {
          "regionCode": "NY",
          "region": "New York",
          "regionId": 43
        },
        "postcode": "10755",
        "street": [
          "123 Oak Ave"
        ],
        "city": "Purchase",
        "telephone": "512-555-1111",
        "countryId": "US"
      }
    ]
  },
  "password": "Password1"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer xxxx_admin_token_xxxx'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;


I hope this blog is useful to create customer using REST API. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach.

Keep liking 👍 Keep sharing 📣 Keep loving ❤️ Keep inspiring 🤩

24 Comments

  1. Tại 888slot com , người chơi có thể lựa chọn nhiều phương thức thanh toán khác nhau như: thẻ ngân hàng nội địa, ví điện tử, và các cổng thanh toán quốc tế. Điều này giúp dễ dàng lựa chọn phương thức phù hợp với nhu cầu cá nhân mà không gặp khó khăn trong quá trình giao dịch. TONY12-12

  2. LuvabetBR, eh? Specifically for us Brazilians! Nice! Looks like they’ve got a good selection of sports and casino games. I’ll be checking out their Brazilian Serie A odds for sure. Come on Brasileirão! Time to win big boys: luvabetbr

  3. Chỉ với một tài khoản duy nhất tại 888slot , bạn có thể tham gia từ cá cược thể thao đến các sòng casino trực tiếp sang trọng nhất. TONY01-06S

  4. Phfun33? Alright, alright, I see you. Looking for some fun? Let’s check if this is where the party is. Check out Phfun33: phfun33

  5. **balmorex pro**

    balmorex is an exceptional solution for individuals who suffer from chronic joint pain and muscle aches.

  6. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  7. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  8. **finessa**

    Finessa is a natural supplement made to support healthy digestion, improve metabolism, and help you achieve a flatter belly.

  9. Gamece88, heard they got some new stuff in. Hopped on and found a couple of hidden gems. Worth a look if you’re bored of your usual haunts. Check out gamece88 – you might find your next favorite game.

  10. Taihq88, decent platform, especially if you’re just starting out. Not too overwhelming and the options are clear. Recommend for beginners. Explore taihq88, it’s beginner friendly.

  11. Hipsph88, looking for something new, stumbled on this. So far, so good! Pretty interesting layout and some different features. Check out what hipsph88 has to offer.

  12. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

Write A Comment