Solved

Can't Perform POST using REST API and Basic Authentication

robertjla
Tourist
3 0 1

I cannot create a record by performing a POST using Shopify's REST API and Basic Authentication. For example, I tried performing a POST to the following URL:
https://{API Key}:{Password}@{MyStore}.myshopify.com/admin/products/{product-id}/metafields.json

Along with the body:
{
"metafield": {
"namespace": "global",
"key": "Test_Metafield",
"value": "Value for test metafield",
"value_type": "string",
"description": "This is the description"
}
}

When I try sending it no metafield gets created for the product. Instead, I get a status 200 with HTML as the response as shown below:

<html>
<body>
<noscript>
<a
href="https://accounts.shopify.com/oauth/authorize?client_id=xxxxxxxxxxxxxxxxx&amp;destination_uuid=xxxxxx...>
</noscript>
<script type="text/javascript" defer>
window.location = "https:\/\/accounts.shopify.com\/oauth\/authorize?client_id=xxxxxxxxxxxxxxxxxxx\u0026destination_uuid=4xxxxxxxxxxxxxxxxxxxx\u0026nonce=xxxxxxxxxxxxxxxxxxx\u0026prompt=merge\u0026redirect_uri=https%3A%2F%2Fxxxxxxx.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\u0026state=xxxxxxxxxxxxxxxxx\u0026ui_locales=en\u0026ux=shop";
</script>
</body>
</html>

I can perform GETs and PUTs in which I can retrieve metafield records as well as update existing metafields. But anytime I perform a POST (or create a new record), I get the same response as above.

Accepted Solution (1)

Jason
Shopify Expert
11190 225 2282

This is an accepted solution.

How are you making the request? Is this via the browser? Postman? Something else? I am guessing you're sending cookies in the request so that's being blocked for good security reasons. Remove those cookies and you may find the result differs.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

View solution in original post

Replies 5 (5)

Jason
Shopify Expert
11190 225 2282

This is an accepted solution.

How are you making the request? Is this via the browser? Postman? Something else? I am guessing you're sending cookies in the request so that's being blocked for good security reasons. Remove those cookies and you may find the result differs.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
robertjla
Tourist
3 0 1

Thanks Jason! I was using Postman. Once I cleared all the cookies I was able to perform the post.

AndreasKör
Visitor
3 0 0

I am currently programming an app that displays orders from Shopify. The program I am using is Delphi (Pascal) and trying to send and receive data using REST. The "GET" commands work without problems but when I try to create an order draft ("POST") for example, it shows me the same error every time as above. What can be done ?

noname101
Visitor
1 0 0

how do you post with the delphi rest api? you must share a sample

Klondev
Shopify Partner
689 82 271

@robertjla If you need any further assistance, we could fix this for you. Its quiet simple.

Stephan | Co-Founder @ Klondev Automation GmbH
- War meine Antwort hilfreich? Dann freu' ich mich über ein Like
- Wurde deine Frage beantwortet? Dann markiere gerne meine Antwort als Akzeptierte Lösung
- Hier findest du unser Profil und unseren Kontakt