I am trying to call the Shopify storefront
GraphQL to create a customer. The customer is being created successfully. However, it does not set the phone number provided for the mutation.
Mutation:
const String customerCreateMutation = r'''
mutation MyMutation($firstName: String, $lastName: String, $email: String!, $password: String!) {
customerCreate(input: {firstName: $firstName, lastName: $lastName, email: $email, password: $password}) {
customer{
acceptsMarketing
createdAt
tags
displayName
email
firstName
id
lastName
phone
}
customerUserErrors {
code
field
message
}
}
}
''';
Graphql:
final MutationOptions _options = MutationOptions(
document: gql(customerCreateMutation),
variables: {
'firstName': "john",
'lastName':"doe",
'email':"john@gmail.com",
'password': "password",
'acceptsMarketing': false,
'phone': "9876543211", /// tried as "+919876543211" too
},
);
final QueryResult result = await _graphQLClient!.mutate(_options);
When I print the customer in the result, I get as result.data['customerCreate']['customer']
, i ma getting the phone as null.
{__typename: Customer, acceptsMarketing: false, createdAt: 2023-10-19T12:56:35Z, tags: [], displayName: asdasd asdasd, email: as9@asdasdad.asd, firstName: asdasd, id: ********, lastName: asdasd, phone: null, lastIncompleteCheckout: null}
Here, it is sending back the phone as null.
I have checked the created customer in the Shopify store also. But it is also blank.
How do I set the phone number of the customer? Is there any other way?
Shopify storefront GraphQL API uses E.164 standard.
for phone number in customerCreate
mutation
means you need to add [+] [country code] [number]
then it will accept the phone number.
try adding +91
+919876543211
phone
variable in your mutation definition// OLD missing phone variable
mutation MyMutation($firstName: String, $lastName: String, $email: String!, $password: String!) {
customerCreate(input: {firstName: $firstName, lastName: $lastName, email: $email, password: $password}) {
// ADD phone variable indefinition
mutation MyMutation($firstName: String, $lastName: String, $email: String!, $phone: String, $password: String!) {
HERE ^
customerCreate(input: {firstName: $firstName, lastName: $lastName, email: $email, phone: $phone, password: $password}) {
HERE ^
if any doubts please comment.