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':"[email protected]",
'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: [email protected], 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 incustomerCreate
mutationmeans you need to add
[+] [country code] [number]
then it will accept the phone number.try adding
+91
I think you missed to pass the
phone
variable in your mutation definitionif any doubts please comment.