Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hi community,
I'm experiencing issues when trying to retrieve information from the localizationExtensions object of a request using the GraphQL API in a C# application. To access the API, I'm utilizing the GraphQL.Client package available on NuGet.
The error I receive when requesting the data is: "The HTTP request failed with status code 'NotFound'".
What leads me to suspect that the problem may not lie within my application is the fact that I have two Shopify stores. One of them is dedicated to development and is somewhat "raw," with no apps except for the development one. This development store contains the Admin API with the necessary scopes enabled. Let's refer to it as the development store. Additionally, there is the client's store with the Admin API app, which has the same selected scopes but in a more commercial environment and is considered the "active" store.
In my development store, I can consume the GraphQL API without any issues. However, the error only occurs in the client's store.
In the client's store, I installed the Shopify GraphiQL app, which allows me to execute queries within the platform itself. I attempted to make the same query that I used in my application and succeeded, indicating that the endpoint exists in some way for the order ID I'm attempting to query.
Could the account I used to create the API app be a factor in this? I'm asking because I observed that some scopes are locked in the selection of Admin API access scope for the user I used to create the client's app on Shopify.
Has anyone encountered a similar issue or knows how to assist me?
Here is my code:
public OrderTaxIdService(string shopifyUrl, string accessToken) { _graphQLClient = new GraphQLHttpClient($"{shopifyUrl}/admin/api/2023-07/graphql.json", new NewtonsoftJsonSerializer()); _graphQLClient.HttpClient.DefaultRequestHeaders.Add("X-Shopify-Access-Token", accessToken); } public async Task<string> GetAsync(string adminGraphQLAPIId) { var orderRequest = new GraphQLRequest { Query = @" query getOrder($id: ID!) { order(id: $id) { id localizationExtensions(first: 1) { edges { node { title value } } } } }", Variables = new { id = adminGraphQLAPIId } }; var orderResponse = await _graphQLClient.SendQueryAsync<OrderResponseType>(orderRequest); var node = orderResponse.Data.Order.LocalizationExtensions.Edges.FirstOrDefault(e => e.Node.Title == "CPF/CNPJ"); return node?.Node.Value ?? string.Empty; }
Query:
{ order(id: "gid://shopify/Order/5508188832050") { id localizationExtensions(first: 1) { edges { node { title value } } } } }
Many thanks for your support.
Solved! Go to the solution
This is an accepted solution.
If there was an issue with the scopes you would expect to get an error stating that you do not have access to that resource, not that the resource is not found.
To debug this I would first suggest confirming that the URL is being built correctly. E.g. Is there an extra ending '\' character that is on the shopifyUrl of the live store?
I would also suggest trying to query for all orders. This would confirm that you do have access to the order resource, so there may be an issue with the specific ID that you are using.
To learn more visit the Shopify Help Center or the Community Blog.
This is an accepted solution.
I identified the problem. Your suggestion about the URL was right. Actually, I was trying to use the custom domain instead of {shop}.myshopify.com. For some unknown reason, I can use my domain for the Admin API without any issues, but the same does not work with GraphQL.
Thank you for your time and guidance.
This is an accepted solution.
If there was an issue with the scopes you would expect to get an error stating that you do not have access to that resource, not that the resource is not found.
To debug this I would first suggest confirming that the URL is being built correctly. E.g. Is there an extra ending '\' character that is on the shopifyUrl of the live store?
I would also suggest trying to query for all orders. This would confirm that you do have access to the order resource, so there may be an issue with the specific ID that you are using.
To learn more visit the Shopify Help Center or the Community Blog.
This is an accepted solution.
I identified the problem. Your suggestion about the URL was right. Actually, I was trying to use the custom domain instead of {shop}.myshopify.com. For some unknown reason, I can use my domain for the Admin API without any issues, but the same does not work with GraphQL.
Thank you for your time and guidance.
+1 to this, I'm able to query the Admin api with the REST client but the GraphQL client does not work for me. I keep getting the 404. Is this intended? Is there a workaround here or should I just use the rest API?