0

I am new to REST Api, I am working on to create customer account via using Rest API but struggling with one error which I am trying to find I authorized account properly but when I try to create new account It gives me an error

First Error

{ "message": "%fieldName is a required field.",
"parameters": {
    "fieldName": "customer"
},

Second Error (After adding Customer Param)

"message": "Please enter a customer email.",

I am not sure what i am doing wrong. I tried to use email param but its not working. Can anyone help me with this.

Software use: Postman Resource: https://devdocs.magento.com/guides/v2.2/rest/tutorials/orders/order-create-customer.html

1

2 Answers 2

1

Step 1: Get authentication key api :

URL - http://example.com/rest/V1/integration/admin/token

METHOD - POST

BODY :

{"username":"adminusername", "password":"adminpassword"}

Step 2 : Call customer registration api : URL - http://example.com/rest/V1/customers

METHOD : POST

HEADER :

Authorization: Bearer key

BODY :

{
  "customer": {
    "id": 0,
    "group_id": 0,
    "default_billing": "string",
    "default_shipping": "string",
    "confirmation": "string",
    "created_at": "string",
    "updated_at": "string",
    "created_in": "string",
    "dob": "string",
    "email": "string",
    "firstname": "string",
    "lastname": "string",
    "middlename": "string",
    "prefix": "string",
    "suffix": "string",
    "gender": 0,
    "store_id": 0,
    "taxvat": "string",
    "website_id": 0,
    "addresses": [
      {
        "id": 0,
        "customer_id": 0,
        "region": {
          "region_code": "string",
          "region": "string",
          "region_id": 0,
          "extension_attributes": {}
        },
        "region_id": 0,
        "country_id": "string",
        "street": [
          "string"
        ],
        "company": "string",
        "telephone": "string",
        "fax": "string",
        "postcode": "string",
        "city": "string",
        "firstname": "string",
        "lastname": "string",
        "middlename": "string",
        "prefix": "string",
        "suffix": "string",
        "vat_id": "string",
        "default_shipping": true,
        "default_billing": true,
        "extension_attributes": {},
        "custom_attributes": [
          {
            "attribute_code": "string",
            "value": "string"
          }
        ]
      }
    ],
    "disable_auto_group_change": 0,
    "extension_attributes": {
      "company_attributes": {
        "customer_id": 0,
        "company_id": 0,
        "job_title": "string",
        "status": 0,
        "telephone": "string",
        "extension_attributes": {}
      },
      "is_subscribed": true,
      "amazon_id": "string",
      "vertex_customer_code": "string"
    },
    "custom_attributes": [
      {
        "attribute_code": "string",
        "value": "string"
      }
    ]
  },
  "password": "string",
  "redirectUrl": "string"
}
1
  • in magento 2.4 after I create new customer and try to login I get 401 unauthorized. If I try to sign in via website I can't. Any ideea what's wrong?
    – Adrian
    Commented Jan 21, 2022 at 13:28
0
In body you've to sent data like the following below.
{
  "customer": {
    "email": "[email protected]",
    "firstname": "your first name",
    "lastname": "your last name",
    "store_id": 1,
    "addresses": [
      {
         "firstname": "your first name",
          "lastname": "your last name",
         "city": "DElhi",
          "street": [
          "117/38"
        ],
        "telephone": "99999999999",
        "country_id": "SA"
      }]
  },
  "password": "admin@123"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.