Create new Product via Admin API

Hello,

i try to create a new product with a fetch call. I am using react native (javascript) to add a new product.

But i get this error:

{“errors”:{“product”:“Required parameter missing or invalid”}}

Thats my code :

var data = {
        "product": {
            "title": "Burton Custom Freestyle 151",
            "body_html": "Good snowboard!",
            "vendor": "Burton",
            "product_type": "Snowboard",
            "tags": ["Barne", "Big Air", "John's Fav"]
        }
    } 
 var header = {
        method: 'POST', 
        headers: {
            'X-Shopify-Access-Token': '4d94c7bb193ee0e1a5a84bb05f44f05d',
            "Content-Type": "application/json",
            "Accept-Charset": "UTF-8"
        },
        body: data
    }
    var url = "https://55960cdbc883891e3ad6493559cc41d5:4d94c7bb193ee0e1a5a84bb05f44f05d@mikeystest.myshopify.com/admin/api/2021-10/products.json"
    var u = await fetch(url, header).then(res => res.text()).then(data => { console.log(data) }).catch((error) => { console.log(error) })

Some ideas why the code dont work?

Got it, just JSON.stringify() the data!

1 Like