This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GraphQL: New mutations for managing customers #7673
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0d2f19
GraphQL: New mutations for managing customers
keharper cc53ddc
Rewrite invalid description
keharper 57a8666
Merge branch '2.4.1-develop' of github.com:magento/devdocs into kh_cu…
keharper 0af5d56
fix example
keharper 195291d
Merge branch '2.4.1-develop' into kh_customer-v2
keharper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/guides/v2.4/graphql/mutations/create-customer-v2.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
group: graphql | ||
title: createCustomerV2 mutation | ||
--- | ||
|
||
The `createCustomerV2` mutation creates a customer account. Use the [`createCustomerAddress` mutation]({{page.baseurl}}/graphql/mutations/create-customer-address.html) to complete the customer profile and define billing and shipping addresses. | ||
|
||
The `createCustomerV2` mutation replaces the `createCustomer` mutation as the means to create a customer account. The input objects differ between these two mutations. The `createCustomer` mutation required the `CustomerInput` object, as did the `updateCustomer` mutation. The attributes required for creating a customer are different than those for updating a customer, but you could not determine this by looking at the schema. The `createCustomerV2` mutation requires the `CustomerCreateInput` object, which it does not share with the [`updateCustomerV2` mutation]({{page.baseurl}}/graphql/mutations/update-customer-v2.html). | ||
|
||
## Syntax | ||
|
||
`mutation: {createCustomerV2(input: CustomerCreateInput!) {CustomerOutput}}` | ||
|
||
## Example usage | ||
|
||
The following call creates a new customer. | ||
|
||
**Request:** | ||
|
||
```graphql | ||
mutation { | ||
createCustomer( | ||
input: { | ||
firstname: "Bob" | ||
lastname: "Loblaw" | ||
email: "[email protected]" | ||
password: "b0bl0bl@w" | ||
is_subscribed: true | ||
} | ||
) { | ||
customer { | ||
firstname | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you leave on purpose all possible customer fields? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're just examples, not meant to show every possibility. Keeping the examples to typical and/or minimal use cases also helps maintain these examples, as I don't have to update the example each time an attribute is added. |
||
lastname | ||
is_subscribed | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Response:** | ||
|
||
```json | ||
{ | ||
"data": { | ||
"createCustomer": { | ||
"customer": { | ||
"firstname": "Bob", | ||
"lastname": "Loblaw", | ||
"email": "[email protected]", | ||
"is_subscribed": true | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Input attributes | ||
|
||
The following table lists the attributes you can use as input for the `createCustomerV2` mutation. | ||
|
||
Attribute | Data Type | Description | ||
--- | --- | --- | ||
`date_of_birth` | String | The customer’s date of birth | ||
`dob` | String | Deprecated. Use `date_of_birth` instead. The customer’s date of birth | ||
keharper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`email` | String! | The customer’s email address | ||
`firstname` | String! | The customer’s first name | ||
`gender` | Int | The customer's gender (Male - 1, Female - 2) | ||
`is_subscribed` | Boolean | Indicates whether the customer subscribes to the store's newsletter | ||
`lastname` | String! | The customer’s last name | ||
`middlename` | String | The customer’s middle name | ||
`password` | String | The customer's password | ||
`prefix` | String | An honorific, such as Dr., Mr., or Mrs. | ||
`suffix` | String | A value such as Sr., Jr., or III | ||
`taxvat` | String | The customer’s Tax/VAT number (for corporate customers) | ||
|
||
## Output attributes | ||
|
||
The `CustomerOutput` object contains the `Customer` object. | ||
|
||
The following table lists the top-level attributes of the `customer` object. See the [`customer` query]({{page.baseurl}}/graphql/queries/customer.html) for complete details about this object. | ||
|
||
{% include graphql/customer-output-24.md %} | ||
|
||
## Errors | ||
|
||
Error | Description | ||
--- | --- | ||
`A customer with the same email address already exists in an associated website.` | The email provided in the `input`.`email` argument belongs to an existing customer. | ||
`"Email" is not a valid email address.` | The value provided in the `input`.`email` argument has an invalid format. | ||
`Field CustomerInput.email of required type String! was not provided` | The `input`.`email` argument was omitted. | ||
`Field "xxx" is not defined by type CustomerInput.` | The `input`.`xxx` argument is undefined. | ||
`Required parameters are missing: First Name` | The `input`.`firstname` argument was omitted or contains an empty value. | ||
|
||
## Related topics | ||
|
||
* [customer query]({{page.baseurl}}/graphql/queries/customer.html) | ||
* [updateCustomerV2 mutation]({{page.baseurl}}/graphql/mutations/update-customer-v2.html) | ||
* [createCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/create-customer-address.html) | ||
* [updateCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/update-customer-address.html) | ||
* [deleteCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/delete-customer-address.html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/guides/v2.4/graphql/mutations/update-customer-email.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
group: graphql | ||
title: updateCustomerEmail mutation | ||
--- | ||
|
||
Use the `updateCustomerEmail` mutation to change the email address for the logged-in customer. | ||
|
||
To return or modify information about a customer, Magento recommends you use customer tokens in the header of your GraphQL calls. However, you also can use [session authentication]({{ page.baseurl }}/get-started/authentication/gs-authentication-session.html). | ||
|
||
## Syntax | ||
|
||
`mutation: updateCustomerEmail(email: String! password: String!): CustomerOutput` | ||
|
||
## Example usage | ||
|
||
The following call updates the customer's email address. | ||
|
||
**Request:** | ||
|
||
```graphql | ||
mutation { | ||
updateCustomerEmail(email: "[email protected]", password: "[email protected]") { | ||
customer { | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Response:** | ||
|
||
```json | ||
{ | ||
"data": { | ||
"updateCustomerEmail": { | ||
"customer": { | ||
"email": "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Input attributes | ||
|
||
The `updateCustomerEmail` mutation requires the following inputs: | ||
|
||
Attribute | Data Type | Description | ||
--- | --- | --- | ||
`email` | String! | The customer's new email address | ||
`password` | String! | The customer's password | ||
|
||
## Output attributes | ||
|
||
The `updateCustomerEmail` mutation returns the `customer` object. | ||
|
||
The following table lists the top-level attributes of the `customer` object. See the [`customer` query]({{page.baseurl}}/graphql/queries/customer.html) for complete details about this object. | ||
|
||
{% include graphql/customer-output-24.md %} | ||
|
||
## Related topics | ||
|
||
* [customer query]({{page.baseurl}}/graphql/queries/customer.html) | ||
* [updateCustomerV2 mutation]({{page.baseurl}}/graphql/mutations/update-customer-v2.html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
group: graphql | ||
title: updateCustomerV2 mutation | ||
--- | ||
|
||
The `updateCustomerV2` mutation updates the personal information in an existing customer account. Use the [`updateCustomerEmail` mutation]({{page.baseurl}}/graphql/mutations/update-customer-email.html) to update the customer's email address. | ||
|
||
The `updateCustomerV2` mutation replaces the `updateCustomer` mutation as the means to update a customer account. The input objects differ between these two mutations. The `updateCustomer` mutation required the `CustomerInput` object, as did the `createCustomer` mutation. Updating a customer does not require any specific attribute, while several attributes are required when you create a customer. You could not determine this by looking at the schema for those mutations. The `updateCustomerV2` mutation requires the `CustomerUpdateInput` object, which it does not share with the [`createCustomerV2` mutation]({{page.baseurl}}/graphql/mutations/create-customer-v2.html). | ||
|
||
To return or modify information about a customer, Magento recommends you use customer tokens in the header of your GraphQL calls. However, you also can use [session authentication]({{ page.baseurl }}/get-started/authentication/gs-authentication-session.html). | ||
|
||
## Syntax | ||
|
||
`mutation: {updateCustomerV2(input: CustomerUpdateInput!) {CustomerOutput}}` | ||
|
||
## Example usage | ||
|
||
The following call updates the first name and the newsletter subscription status for a specific customer. | ||
|
||
**Request:** | ||
|
||
```graphql | ||
mutation { | ||
updateCustomerV2( | ||
input: { | ||
firstname: "Robert" | ||
is_subscribed: false | ||
} | ||
) { | ||
customer { | ||
firstname | ||
is_subscribed | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Response:** | ||
|
||
```json | ||
{ | ||
"data": { | ||
"updateCustomerV2": { | ||
"customer": { | ||
"firstname": "Robert", | ||
"is_subscribed": false | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Input attributes | ||
|
||
The following table lists the attributes you can use as input for the `updateCustomerV2` mutation. | ||
|
||
Attribute | Data Type | Description | ||
--- | --- | --- | ||
`date_of_birth` | String | The customer’s date of birth | ||
`dob` | String | Deprecated. Use `date_of_birth` instead. The customer’s date of birth | ||
`firstname` | String | The customer’s first name | ||
`gender` | Int | The customer's gender (Male - 1, Female - 2) | ||
`is_subscribed` | Boolean | Indicates whether the customer subscribes to the store's newsletter | ||
`lastname` | String | The customer’s last name | ||
`middlename` | String | The customer’s middle name | ||
`password` | String | The customer's password | ||
`prefix` | String | An honorific, such as Dr., Mr., or Mrs. | ||
`suffix` | String | A value such as Sr., Jr., or III | ||
`taxvat` | String | The customer’s Tax/VAT number (for corporate customers) | ||
|
||
## Output attributes | ||
|
||
The `CustomerOutput` object contains the `Customer` object. | ||
|
||
The following table lists the top-level attributes of the `customer` object. See the [`customer` query]({{page.baseurl}}/graphql/queries/customer.html) for complete details about this object. | ||
|
||
{% include graphql/customer-output-24.md %} | ||
|
||
## Related topics | ||
|
||
* [customer query]({{page.baseurl}}/graphql/queries/customer.html) | ||
* [createCustomerV2 mutation]({{page.baseurl}}/graphql/mutations/create-customer-v2.html) | ||
* [createCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/create-customer-address.html) | ||
* [updateCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/update-customer-address.html) | ||
* [updateCustomerEmail mutation]({{page.baseurl}}/graphql/mutations/update-customer-email.html) | ||
* [deleteCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/delete-customer-address.html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.