Invalid global id

krishna9
Shopify Partner
3 0 2

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

Busfox
Shopify Staff
Shopify Staff
619 48 95

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,

 

Tiger_Rana
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
Tiger_Rana
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
throbi
New Member
2 0 0

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

 image.png

 

0 Likes
mnf
Tourist
9 0 0

You may have already resolved your issue, but just in case someone else comes along with the same problem.

Your problem is that you are not using the storefrontId in your query.  You are using the admin api id.  As mentioned in a previous response, this information is explained here: https://shopify.dev/tutorials/migrate-from-rest-api-to-graphql.

But the key part is to find the storefrontId.  The easiest way to find this id is to install the Shopify GraphiQL App in your store and then use the "explorer" to query your store data (here's a link to the explorer that is web based: https://shopify-graphiql-app.shopifycloud.com).

Here is the query you can use to get the id (but replace "your-product-id" with your actual product id; this can be found in many places, but possibly the easiest is to go to the product page in your shopify store admin and look in the url; the id will be a series of digits at the end of the url).

{product(id: "gid://shopify/Product/your-product-id") {id storefrontId title}}

I hope this helps.

0 Likes