ShopifySharp icon indicating copy to clipboard operation
ShopifySharp copied to clipboard

404 error migrating from ProductService to GraphQL query.

Open jeleleven opened this issue 5 months ago • 2 comments

Hello @nozzlegear,

Thank you for your work on this. It's been very useful.

As I understand it, ProductService has been depreciated and I will need to move over to GraphQL going forward.

I am working on moving my code over to GraphQL, but I'm getting a 404 error when I use the sample code. The issue is happening at the PostAsync call, returning a '404 Not Found' HttpException.

I am able to use the following code to retreive all products from our store without issue: var productService = new ProductService(shopifyUrl, apiToken)

When I use the sample code, it does not work:

var graphService = new GraphService(shopifyUrl, apiToken);

var graphRequest = new GraphRequest
{
    Query =
        """
        query {
            products(first: 3, query: "status:ACTIVE") {
                pageInfo {
                    startCursor
                    endCursor
                    hasNextPage
                    hasPreviousPage
                }
                nodes {
                    id
                    # Get the product's REST Id too
                    legacyResourceId
                    title
                    handle
                    hasOnlyDefaultVariant
                    variantsCount {
                        count
                    }
                }
            }
        }
        """,
}

var graphResult = await graphService.PostAsync<Shopify_API_Classes.ListProductsResult>(graphRequest)

I have verified that my shopifyUrl variable is the *.myshopify.com url, as was noted in the Wiki.

Do you see something I may be missing here?

Thanks!

jeleleven avatar Apr 28 '25 14:04 jeleleven