Why is the collects endpoint failing on Shopify API?

HV5150
Shopify Partner
1 0 1
I'm having issues with the 'collects' endpoint when using the API. 
I am trying to add a product to a custom collection using the following curl:
 
curl 'https://{{api_key}}:{{api_password}}@{{store_name}}.myshopify.com/admin/api/2023-01/collects.json' \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {{access_token}}' \
-d '{
    "collect": {[
        "product_id": {{product_id}},
        "collection_id": {{collection_id}}
    ]}
}'
I can confirm that I am using the correct keys and password etc, as calls to other endpoints work fine. I have write_products and read_products accesses. 
 
The API returns the following:
 
<html>
<body>
<noscript>
<a
href="https://accounts.shopify.com/oauth/authorize?client_id=xxxxxx&amp;destination_uuid=xxxxx&amp;nonce=xxxx&amp;prompt=merge&amp;redirect_uri=https%3A%2F%2Fxxxxxxx.myshopify.com%2Fadmin%2Fauth%2Fidentity%2Fcallback&amp;response_type=code&amp;scope=email%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fdestinations.readonly%20openid%20profile%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.collaborator-relationships.readonly%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fbanking.manage%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fmerchant-setup-dashboard.graphql%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshopify-chat.admin.graphql%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fflow.workflows.manage%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Forganization-identity.manage&amp;state=xxxxxx&amp;ui_locales=en&amp;ux=shop">Continue</a>
</noscript>

<script type="text/javascript" defer>
window.location = "https:\/\/accounts.shopify.com\/oauth\/authorize?client_id=xxxxxx\u0026destination_uuid=xxxx\u0026nonce=xxxx\u0026prompt=merge\u0026redirect_uri=https%3A%2F%2Fxxxxxx.myshopify.com%2Fadmin%2Fauth%2Fidentity%2Fcallback\u0026response_type=code\u0026scope=email%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fdestinations.readonly%20openid%20profile%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.collaborator-relationships.readonly%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fbanking.manage%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fmerchant-setup-dashboard.graphql%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fshopify-chat.admin.graphql%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fflow.workflows.manage%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Forganization-identity.manage\u0026state=xxxx\u0026ui_locales=en\u0033xz=shop";
</script>
</body>

</html>

 
Any ideas what I am doing wrong?
 
Reply 1 (1)

flareAI
Shopify Partner
2405 223 534

Hello @HV5150,


I am Gina from flareAI app helping Shopify merchants get $5Million+ in sales from Google Search, on autopilot.


It seems like the API call you are making is redirecting you to the authorization page, which means that the API credentials are not being recognized. Here are a few things to check.


1. Make sure that you are using the correct API version in the API call
In your example, you are using 2023-01. Make sure that this is the correct version for your store. You can check the API version by going to your Shopify admin and clicking on Apps > Manage private apps > your app > API details.

2. Double-check that you have the correct permissions for the API call.
In your case, you need the write_customers and read_customers permissions. You can check the permissions by going to your Shopify admin and clicking on Apps > Manage private apps > your app > Admin API.

3. Ensure that you are passing the correct JSON data in the API call
In your example, the JSON data is not properly formatted. The correct format should be:

{
"collect": {
"product_id": {{product_id}},
"collection_id": {{collection_id}}
}
}

Make sure to remove the square brackets around the product_id and collection_id values.

4. Make sure that you have the correct syntax in your API call. In your example, you have a colon instead of a comma after collect. Change it to a comma:

{
"collect": {
"product_id": {{product_id}},
"collection_id": {{collection_id}}
}
}


If none of these suggestions solve your problem, I recommend reaching out to Shopify's API support team for further assistance. They will be able to help you troubleshoot the issue and identify any errors in your API call.


Gina

flareAI : Get Sales from Google Search, on Autopilot
$10+ billion in eCommerce on Google Search, every day. Find out how much you are missing