Posting a product using Rest

Solved
Ruben00001
Excursionist
20 2 3

I'm using Postman to make API requests using the REST reference (link) and I'm stuck on how to post a product.

 

I've managed to get products.

 

I used the same admin api credentials as with my GET request for my POST request:

 

https://{{API key}}:{{password}}@{{store-name}}.myshopify.com/admin/api/2020-01/products.json

With body from docs:

 

{
  "product": {
    "title": "Burton Custom Freestyle 151",
    "body_html": "<strong>Good snowboard!</strong>",
    "vendor": "Burton",
    "product_type": "Snowboard",
    "tags": [
      "Barnes & Noble",
      "John's Fav"
    ]
  }
}

I get a HTML response I don't understand.

 

Attempting the solution in another thread, I've tried to add a X-Shopify-Access-Token key to the request header but I'm not sure what credential to put there (I've tried my storefront access token) and haven't got it to work.

 

Any help will be much appreciated. 

 

 

Accepted Solution (1)

Accepted Solutions
Ruben00001
Excursionist
20 2 3

This is an accepted solution.

UPDATE.

 

I made a successful POST request in the following format:

 

https://{site-name}.myshopify.com/admin/api/2020-01/products.json

with header 'X-Shopify-Access-Token' and value of the password from the Admin API.

View solution in original post

Replies 2 (2)
Ruben00001
Excursionist
20 2 3

This is an accepted solution.

UPDATE.

 

I made a successful POST request in the following format:

 

https://{site-name}.myshopify.com/admin/api/2020-01/products.json

with header 'X-Shopify-Access-Token' and value of the password from the Admin API.

View solution in original post

zulmeep
New Member
2 0 0

Hi! 

I tried different options for the following API call but it is still not working and I was wondering what you did differently.

Here is my current code:

// Create 1 Shopify Product -- TEST

const url = 'https://STORE-NAME.myshopify.com/admin/api/2021-10/products.json'

let body = {"product":[
    { 
    "product": {
        "title":'test-new-product',
        "body_html":null,
        "vendor":'Me',
        "product_type":'test',
        "published":false,
        "published_at": null,
        "status": "active",
        "published_scope": "global"
    }
    }
]}
const options = {
         method: 'POST',
         headers: {
            'X-Shopify-Access-Token': {API_PASSWORD}
         },
        body: JSON.stringify(body)
        };

let response = await remoteFetchAsync(url,options)
let product = await response.json()

console.log(product)

 

This is the response I get: 
errors: "[API] Invalid API key or access token (unrecognized login or wrong password)"


Thank you so much!