Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit ca00b80

Browse files
authored
Merge pull request #7673 from magento/kh_customer-v2
GraphQL: New mutations for managing customers
2 parents e0005c0 + 195291d commit ca00b80

File tree

6 files changed

+269
-0
lines changed

6 files changed

+269
-0
lines changed

src/_data/toc/graphql.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ pages:
172172
- label: createCustomer mutation
173173
url: /graphql/mutations/create-customer.html
174174

175+
- label: createCustomerV2 mutation
176+
url: /graphql/mutations/create-customer-v2.html
177+
exclude_versions: ["2.3"]
178+
175179
- label: createCustomerAddress mutation
176180
url: /graphql/mutations/create-customer-address.html
177181

@@ -275,6 +279,14 @@ pages:
275279
- label: updateCustomer mutation
276280
url: /graphql/mutations/update-customer.html
277281

282+
- label: updateCustomerEmail mutation
283+
url: /graphql/mutations/update-customer-email.html
284+
exclude_versions: ["2.3"]
285+
286+
- label: updateCustomerV2 mutation
287+
url: /graphql/mutations/update-customer-v2.html
288+
exclude_versions: ["2.3"]
289+
278290
- label: updateCustomerAddress mutation
279291
url: /graphql/mutations/update-customer-address.html
280292

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
group: graphql
3+
title: createCustomerV2 mutation
4+
---
5+
6+
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.
7+
8+
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).
9+
10+
## Syntax
11+
12+
`mutation: {createCustomerV2(input: CustomerCreateInput!) {CustomerOutput}}`
13+
14+
## Example usage
15+
16+
The following call creates a new customer.
17+
18+
**Request:**
19+
20+
```graphql
21+
mutation {
22+
createCustomerV2(
23+
input: {
24+
firstname: "Bob"
25+
lastname: "Loblaw"
26+
27+
password: "b0bl0bl@w"
28+
is_subscribed: true
29+
}
30+
) {
31+
customer {
32+
firstname
33+
lastname
34+
email
35+
is_subscribed
36+
}
37+
}
38+
}
39+
```
40+
41+
**Response:**
42+
43+
```json
44+
{
45+
"data": {
46+
"createCustomer": {
47+
"customer": {
48+
"firstname": "Bob",
49+
"lastname": "Loblaw",
50+
"email": "[email protected]",
51+
"is_subscribed": true
52+
}
53+
}
54+
}
55+
}
56+
```
57+
58+
## Input attributes
59+
60+
The following table lists the attributes you can use as input for the `createCustomerV2` mutation.
61+
62+
Attribute | Data Type | Description
63+
--- | --- | ---
64+
`date_of_birth` | String | The customer’s date of birth
65+
`dob` | String | Deprecated. Use `date_of_birth` instead. The customer’s date of birth
66+
`email` | String! | The customer’s email address
67+
`firstname` | String! | The customer’s first name
68+
`gender` | Int | The customer's gender (Male - 1, Female - 2)
69+
`is_subscribed` | Boolean | Indicates whether the customer subscribes to the store's newsletter
70+
`lastname` | String! | The customer’s last name
71+
`middlename` | String | The customer’s middle name
72+
`password` | String | The customer's password
73+
`prefix` | String | An honorific, such as Dr., Mr., or Mrs.
74+
`suffix` | String | A value such as Sr., Jr., or III
75+
`taxvat` | String | The customer’s Tax/VAT number (for corporate customers)
76+
77+
## Output attributes
78+
79+
The `CustomerOutput` object contains the `Customer` object.
80+
81+
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.
82+
83+
{% include graphql/customer-output-24.md %}
84+
85+
## Errors
86+
87+
Error | Description
88+
--- | ---
89+
`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.
90+
`"Email" is not a valid email address.` | The value provided in the `input`.`email` argument has an invalid format.
91+
`Field CustomerInput.email of required type String! was not provided` | The `input`.`email` argument was omitted.
92+
`Field "xxx" is not defined by type CustomerInput.` | The `input`.`xxx` argument is undefined.
93+
`Required parameters are missing: First Name` | The `input`.`firstname` argument was omitted or contains an empty value.
94+
95+
## Related topics
96+
97+
* [customer query]({{page.baseurl}}/graphql/queries/customer.html)
98+
* [updateCustomerV2 mutation]({{page.baseurl}}/graphql/mutations/update-customer-v2.html)
99+
* [createCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/create-customer-address.html)
100+
* [updateCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/update-customer-address.html)
101+
* [deleteCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/delete-customer-address.html)

src/guides/v2.4/graphql/mutations/create-customer.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ group: graphql
33
title: createCustomer mutation
44
---
55

6+
{:.bs-callout-warning}
7+
The `createCustomer` mutation has been deprecated. Use the [createCustomerV2]({{page.baseurl}}/graphql/mutations/create-customer-v2.html) mutation instead.
8+
69
Use the `createCustomer` mutation to create a new customer.
710

811
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).
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
group: graphql
3+
title: updateCustomerEmail mutation
4+
---
5+
6+
Use the `updateCustomerEmail` mutation to change the email address for the logged-in customer.
7+
8+
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).
9+
10+
## Syntax
11+
12+
`mutation: updateCustomerEmail(email: String! password: String!): CustomerOutput`
13+
14+
## Example usage
15+
16+
The following call updates the customer's email address.
17+
18+
**Request:**
19+
20+
```graphql
21+
mutation {
22+
updateCustomerEmail(email: "[email protected]", password: "[email protected]") {
23+
customer {
24+
email
25+
}
26+
}
27+
}
28+
```
29+
30+
**Response:**
31+
32+
```json
33+
{
34+
"data": {
35+
"updateCustomerEmail": {
36+
"customer": {
37+
"email": "[email protected]"
38+
}
39+
}
40+
}
41+
}
42+
```
43+
44+
## Input attributes
45+
46+
The `updateCustomerEmail` mutation requires the following inputs:
47+
48+
Attribute | Data Type | Description
49+
--- | --- | ---
50+
`email` | String! | The customer's new email address
51+
`password` | String! | The customer's password
52+
53+
## Output attributes
54+
55+
The `updateCustomerEmail` mutation returns the `customer` object.
56+
57+
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.
58+
59+
{% include graphql/customer-output-24.md %}
60+
61+
## Related topics
62+
63+
* [customer query]({{page.baseurl}}/graphql/queries/customer.html)
64+
* [updateCustomerV2 mutation]({{page.baseurl}}/graphql/mutations/update-customer-v2.html)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
group: graphql
3+
title: updateCustomerV2 mutation
4+
---
5+
6+
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.
7+
8+
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).
9+
10+
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).
11+
12+
## Syntax
13+
14+
`mutation: {updateCustomerV2(input: CustomerUpdateInput!) {CustomerOutput}}`
15+
16+
## Example usage
17+
18+
The following call updates the first name and the newsletter subscription status for a specific customer.
19+
20+
**Request:**
21+
22+
```graphql
23+
mutation {
24+
updateCustomerV2(
25+
input: {
26+
firstname: "Robert"
27+
is_subscribed: false
28+
}
29+
) {
30+
customer {
31+
firstname
32+
is_subscribed
33+
}
34+
}
35+
}
36+
```
37+
38+
**Response:**
39+
40+
```json
41+
{
42+
"data": {
43+
"updateCustomerV2": {
44+
"customer": {
45+
"firstname": "Robert",
46+
"is_subscribed": false
47+
}
48+
}
49+
}
50+
}
51+
```
52+
53+
## Input attributes
54+
55+
The following table lists the attributes you can use as input for the `updateCustomerV2` mutation.
56+
57+
Attribute | Data Type | Description
58+
--- | --- | ---
59+
`date_of_birth` | String | The customer’s date of birth
60+
`dob` | String | Deprecated. Use `date_of_birth` instead. The customer’s date of birth
61+
`firstname` | String | The customer’s first name
62+
`gender` | Int | The customer's gender (Male - 1, Female - 2)
63+
`is_subscribed` | Boolean | Indicates whether the customer subscribes to the store's newsletter
64+
`lastname` | String | The customer’s last name
65+
`middlename` | String | The customer’s middle name
66+
`password` | String | The customer's password
67+
`prefix` | String | An honorific, such as Dr., Mr., or Mrs.
68+
`suffix` | String | A value such as Sr., Jr., or III
69+
`taxvat` | String | The customer’s Tax/VAT number (for corporate customers)
70+
71+
## Output attributes
72+
73+
The `CustomerOutput` object contains the `Customer` object.
74+
75+
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.
76+
77+
{% include graphql/customer-output-24.md %}
78+
79+
## Related topics
80+
81+
* [customer query]({{page.baseurl}}/graphql/queries/customer.html)
82+
* [createCustomerV2 mutation]({{page.baseurl}}/graphql/mutations/create-customer-v2.html)
83+
* [createCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/create-customer-address.html)
84+
* [updateCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/update-customer-address.html)
85+
* [updateCustomerEmail mutation]({{page.baseurl}}/graphql/mutations/update-customer-email.html)
86+
* [deleteCustomerAddress mutation]({{page.baseurl}}/graphql/mutations/delete-customer-address.html)

src/guides/v2.4/graphql/mutations/update-customer.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ group: graphql
33
title: updateCustomer mutation
44
---
55

6+
{:.bs-callout-warning}
7+
The `updateCustomer` mutation has been deprecated. Use the [updateCustomerV2]({{page.baseurl}}/graphql/mutations/update-customer-v2.html) mutation instead.
8+
69
Use the `updateCustomer` mutation to update the customer's personal information.
710

811
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).

0 commit comments

Comments
 (0)