How to create products using Postman

SLL
New Member
8 0 0

I'm new to Shopify so please excuse me if I've not done this or that...

 

 

I've created a private store (signed up to the partner programme), and made notes of the various API keys and secrets.

 

I downloaded the ShopifySharp application and pulled out of it the bits needed to create a product, and found from debugging the code that I needed an Access Token.  In Postman, I created a GET request to:

https://<my-store>.myshopify.com/admin/api/2019-04/storefront_access_tokens.json and added the necessary basic auth credentials and was ale to get my store's access token: hurrah!

 

Next, since the C# app was failing with bad request, I decided to use Postman to try and create a POST product request to https://<my-store>.myshopify.com/admin/api/2019-04/products.json.  I added the necessary basic auth details as above, added two headers: X-Shopify-Access-Token (and set it to the value of the token returned above) and also Accept: application/json.  

 

and finally, in the body of the request, I pasted in

 

{"product": {"title": "Burton Custom Freestyle 151","body_html": "<strong>Good snowboard!</strong>","vendor": "Burton","product_type": "Snowboard","variants": [{"option1": "First","price": "10.00","sku": "123"}]}}

 

However, when the request is posted, the response is 200 and a whole bunch of HTML (snippet below)

 

<body>
  <noscript>
    <a
...
</noscript>

  <script type="text/javascript">
    window.location = "https:\/\/app....
  </script>
</body>

</html>

 

This is not what I expected.

 

Any ideas why this simple request is failing?

 

 

 

 

Sai.

Replies 4 (4)

SLL
New Member
8 0 0

OK, found this post: https://community.shopify.com/c/Shopify-APIs-SDKs/SHOPIFY-API-POST-requests-do-not-work-with-POSTMAN... and when I duly delete ALL cookies, I now get

 

{
    "errors""[API] Invalid API key or access token (unrecognized login or wrong password)"
}
 
but the User name and Password are the same that I used for the GET request?
SLL
New Member
8 0 0

Thanks to the ShopifySharp app, I am now able to create products on Shopify!  The problem is that the access token returned by calling https://Orcus-ltd.myshopify.com/admin/api/2019-04/storefront_access_tokens.json is not the token that I need to be able to create products!

The token that you need is to do this is actually your API password (API Key blah, Password ...).

 

With this APi password inserted as the value for X-Shopify-Access-Token, the request now fails in Postman with "product": "Required parameter missing or invalid" - presuambly because the example JSONs that Shopify provide for you is incomplete.

 

But in the C# App, this works!!

 

All I need now is the complete JSON to create products, and not just the snippet that Shopify provide.

AshleyVaz
Visitor
1 0 0

Can you please share your C# code snippet?, I was facing the same issue and cant figure our how to solve the issue.

SLL
New Member
8 0 0

Hi,

 

Apologies for the late reply but I downloaded and made use of the library by NozzleGear (on GitHub).  Source code is available too.

I looked at how his tests did things, and took it from there (in essense, I set up the objects that the calls required before making the call).

eg:

 

...

product = await ProductService.CreateAsync(new ShopifyDataStructures.Entities.Product()
{
Title = title,
BodyHtml = descriptionHtml,
Vendor = manufacturer,
ProductType = productType,
Handle = handle,
Tags = tags,
Published = published,
PublishedScope = publishedScope,
Images = shopifyImages,
}, options);

#region Update the product

// https://shopify.dev/docs/admin-api/rest/reference/products/product-variant?api[version]=2019-07#crea...
foreach (var pv in product.Variants)
{
pv.SKU = myProductCode;
pv.Barcode = barcode;
pv.Weight = weight;
pv.WeightUnit = weightUnit;
pv.Price = price;
pv.InventoryManagement = "Shopify"; // To set inventory, InventoryManagement must be Shopify
pv.InventoryPolicy = "deny"; // Not alloewd to buy if ZERO stock.
pv.CompareAtPrice = price;

productVariant = await ProductVariantService.UpdateAsync(pv.Id.Value, pv);
}

...

 

I'm in the situation now where I need to update the Order API call to use the Link response in the response.headers, but, this is turning out to be ball-ache ie the Shopify docs aren't much help to me 😞