POST Product through REST API returns 400 error

I’m trying to POST new product through REST API but getting 400 error without much details:

HTTP error:<400 , Bad Request Error : {"errors":{"product":"Required parameter missing or invalid"}}>
X-Request-ID: bc258e03-878e-4253-a3ad-8b30d63155ac

From API docs I see only ‘title’ element is necessary, which is present. Please give me more details what parameter I missed?

Used following schema to make a JSON request:

<application xmlns="http://wadl.dev.java.net/2009/02">
   <doc xml:lang="en" title="https://mystorename.myshopify.com"/>
   <grammars>
   <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="product">
    <xs:complexType>
      <xs:sequence>
        <xs:element type="xs:string" name="title"/>
        <xs:element type="xs:string" name="vendor"/>
        <xs:element type="xs:string" name="product_type"/>
	<xs:element type="xs:string" name="handle"/>
	<xs:element type="xs:string" name="published_scope"/>
	<xs:element type="xs:string" name="tags"/>
	<xs:element type="xs:boolean" name="published"/>
              <xs:element name="variants">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:decimal" name="price"/>
                    <xs:element type="xs:string" name="sku"/>
		    <xs:element type="xs:string" name="inventory_policy"/>
                    <xs:element type="xs:string" name="fulfillment_service"/>
                    <xs:element type="xs:string" name="inventory_management"/>
		    <xs:element type="xs:boolean" name="taxable"/>
                    <xs:element type="xs:string" name="barcode"/>
		    <xs:element type="xs:int" name="inventory_quantity"/>
		    <xs:element type="xs:boolean" name="requires_shipping"/>					
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
   </grammars>
   <resources base="https://mystorename.myshopify.com">
      <resource path="admin/api/2023-07/products.json" id="Products.json">
         <doc xml:lang="en" title="Products.json"/>
         <param name="Authorization" type="xs:string" required="false" default="" style="header" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
         <method name="POST" id="Products.json">
            <doc xml:lang="en" title="Products.json"/>
            <request>
			    <representation mediaType="application/json; charset=utf-8" element="product" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
            </request>
			<response status="200">
				<representation mediaType="application/json; charset=utf-8"/>
			</response>
         </method>
      </resource>
   </resources>
</application>  

Hi Sp1ke,

This error message implies that a required parameter in your POST request is either missing or invalid.

In your XML schema, you have mentioned a lot of parameters, but remember that only the title is required. All other parameters are optional.

Here’s a minimal POST request for creating a product:

{
  "product": {
    "title": "Burton Custom Freestyle 151",
    "variants": [
      {
        "price": "199.99"
      }
    ]
  }
}

If you are indeed including the title in your request and are still facing this error, make sure that the title is not an empty string or null. Also, ensure that the product object is properly nested in your JSON request.

If you are including any additional parameters in your request, check to ensure their values are valid too. For example, if you include the variants parameter, then the price field insidevariants` must be a string that represents a valid decimal number. Also, make sure you have the correct permissions to create a product in the store.

Hope this helps!