Product Delete API Error

Highlighted
New Member
1 0 0

Hi All,

We are looking for advice for our shopify apps.

We were trying to delete product and follow the tutorial :

https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/productdelete

Here is our code :

     var shopifyId;
                for(value of req.user.listOfProducts)
                {
                    if(value.productId===req.body.deleteId)
                    {
                       shopifyId=value.shopifyId
                    }
                }

        await fetch("https://xxxxxxx.myshopify.com/admin/api/2020-07/graphql.json", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "X-Shopify-Access-Token": "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"
            },
            body: JSON.stringify({
                query: `mutation productDelete($input: ProductDeleteInput!) {
                    productDelete(input: $input) {
                      deletedProductId
                      shop {
                        id
                      }
                      userErrors {
                        field
                        message
                      }
                    }
                  }`,
                variables: {
                    "input": {
                        "id": shopifyId
                    }
                }

            })
        })

 

However, the error occurred and we has confirmed the ShopifyID is correct :

shopify err data{"data":{productDelete":null},"errors":[{"message":"invalid id","locations":[{"line":2,"column":21}],"path":["productDelete"]}],"extensions":{"cost":{"reqestedQueryCost":10,"actualQueryCost":0,"throttleStatus":{"maximumAvailable":1000,"currentlyAvailable":1000,"restoreRate":50}}}}

 

Please kindly advise is there is any solution

Cheers!  

Cat

0 Likes