Magento 2 How to create and update customer using GraphQL

In this article, we will show you how to create customer and update customer.

Create customer

Use the createCustomer mutation to create a new customers. To return or modify information about a customer. Customer token no need to set in the header of GraphQL for customer registration.

Syntax

mutation {
    createCustomer(
    input: CustomerInput!
  ) {
    CustomerOutput
  }
}

You can use the following example for create customer.

Request

saveCopyzoom_out_map
mutation{ createCustomer( input: { firstname: "Developer" lastname: "Test" email: "devtest@example.com" password: "Dev@test123" is_subscribed: true } ){ customer{ firstname lastname email is_subscribed } } }

Response

saveCopyzoom_out_map
{ "data": { "createCustomer": { "customer": { "firstname": "Developer", "lastname": "Test", "email": "devtest@example.com", "is_subscribed": true } } } }

Update Customer

Use updateCustomer mutation to update the customer’s personal information. To return or modify information about a customer. Customer token need to set in the header of GraphQL using Generate Customer Token.

Syntax

mutation {
  updateCustomer(
    input: CustomerInput!
  ) {
    CustomerOutput
  }
}

Request

saveCopyzoom_out_map
mutation{ updateCustomer( input:{ firstname: "Devtest" lastname: "Developer" } ){ customer{ firstname lastname } } }

Response

saveCopyzoom_out_map
{ "data": { "updateCustomer": { "customer": { "firstname": "Devtest", "lastname": "Developer" } } } }

That's it!!

If you are looking for more GraphQL solutions then check out our another article which is List of GraphQL Queries and Mutations for Magento 2.

I hope this article helps you to find what you were looking for.

Bookmark it for your future reference. Do comment below if you have any other questions on that.

P.S. Do share this article with your team.




Recent Articles
Tags
Newsletter
Chrome Extension
Copyright © 2024 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off