Invalid global id

Highlighted
Shopify Partner
3 0 2

Hi All, I have creating the checkout using GraphQL mutation and getting error message "Invalid global id `2015021465715`"

1 Like
Highlighted
Shopify Staff
Shopify Staff
619 48 94

Hi @krishna9,

 

The error message is correct, that id is invalid. I would take a look at our guide for migrating to GraphQL from REST:https://help.shopify.com/en/api/graphql-admin-api/migrating-from-rest. Let's say the id you shared is for a product, your GID would be gid://shopify/Product/2015021465715.

 

Cheers,

 

1 Like
Highlighted
New Member
2 0 0

Sir i am using

String graphID = "gid://shopify/Product/12651191402543";

but i am still getting this error:

Invalid global id `gid://shopify/Product/12651191402543`

please help me. i can share my code

0 Likes
Highlighted
New Member
2 0 0

here is my code for creating checkout using GraphQLMutationQuery:

 

String graphID = "gid://shopify/Product/12651191402543";

Storefront.CheckoutCreateInput input = new Storefront.CheckoutCreateInput()
.setLineItemsInput(Input.value(Collections.singletonList(
new Storefront.CheckoutLineItemInput(2, new ID(graphID)))));

Storefront.MutationQuery query = null;
try {
query = Storefront.mutation(mutationQuery -> mutationQuery
.checkoutCreate(input,
createPayloadQuery ->
createPayloadQuery.checkout(Storefront.CheckoutQuery::webUrl
)
.userErrors(userErrorQuery -> userErrorQuery
.field()
.message()
)
)
);
}catch (Exception error){
Log.e("query", error.getMessage(), error);
activity.runOnUiThread(() -> Toast.makeText(activity, "Error in checkout, sorry.", Toast.LENGTH_SHORT).show());
return;
}

activity.runOnUiThread(() -> Toast.makeText(activity, "Processing checkout, please wait", Toast.LENGTH_SHORT).show());

graphClient.mutateGraph(query).enqueue(new GraphCall.Callback<Storefront.Mutation>() {
@Override public void onResponse(@NonNull GraphResponse<Storefront.Mutation> response) {
try {
for (Error error:response.errors()) {
Log.e("checkout Error", error.message());
activity.runOnUiThread(() -> Toast.makeText(activity, error.message(), Toast.LENGTH_SHORT).show());
}
if (!response.data().getCheckoutCreate().getUserErrors().isEmpty()) {
} else {
String checkoutId = response.data().getCheckoutCreate().getCheckout().getId().toString();
String checkoutWebUrl = response.data().getCheckoutCreate().getCheckout().getWebUrl();
Log.e("checkoutResponse", "checkout (id, url) : (" + checkoutId +
", " + checkoutWebUrl + ")");
}
}catch (Exception error){
Log.e("checkout RuntimeError", error.getMessage(), error);
return;
}
}

@Override public void onFailure(@NonNull GraphError error) {
Log.e("checkout Error", error.getMessage(), error);
}
});

 

0 Likes
Highlighted
New Member
2 0 0

I had the same issue with customers. This works for me:

 image.png

 

0 Likes