user3779698
user3779698

Reputation: 1

Bigcommerce - Posting Products to the API

I am trying to post a product to my bigcommerce staging area. The BC api response has thus far been helpful in pointing out why my XML schema was not compliant but now it only returns a 500 error.

<product>
 <name>xbox</name>
 <type>physical</type>
 <description>this is a test item</description>
 <price>499.99</price>
 <categories>
  <categories>18</categories>
 </categories>
 <availability>available</availability>
 <weight>0.5</weight>
</product>

Since the api has successfully parsed my xml to point out errors I am sure that my headers are correct (applicaiton/xml) and the error itself is a 500 error with the message "An error occurred processing the request"

I have consulted the BC Api page for this procedure and even gone as far as to mimic the json object they provide.

{
"name": "xbox",
"type": "physical",
"description": "this is a test item",
"price": "499.99",
"categories": { "categories": "18" },
"availability": "available",
"weight": "0.5"

}

The json above posted just fine (after changing my header to application/json). For the life of me why is the XML not going through? I have posted customers and orders through BC with relatively no problem but this is bugging me.

Upvotes: 0

Views: 467

Answers (3)

jerwood
jerwood

Reputation: 548

Your formatting of the categories section is incorrect, it should be an array of numbers.

{
    "name": "xbox",
    "type": "physical",
    "description": "this is a test item",
    "price": "499.99",
    "categories": [ 18 ],
    "availability": "available",
    "weight": "0.5"
}

Perhaps there is a typo in the docs.

Upvotes: 0

natep
natep

Reputation: 126

I had the same problem when posting products to BigCommerce. The solution I found was very simple. When posting a product with only one category, the category must be included twice. I have no idea why, but that's what made it work for me.

<product>
 <name>xbox</name>
 <type>physical</type>
 <description>this is a test item</description>
 <price>499.99</price>
 <categories>
   <category>18</category>
   <category>18</category>
 </categories>
 <availability>available</availability>
 <weight>0.5</weight>
</product>

Be sure to use "category" as your element name inside the "categories" array.

UPDATE: I just realized that I didn't include the JSON format, which is what you're working with. It's simpler.

"categories" : [ 18, 18],

Be sure to use square brackets.

Upvotes: 1

developerscott
developerscott

Reputation: 923

I think the issue is how you have your category data. Try using value instead of categories within the categories array.

<product>
 <name>xbox</name>
 <type>physical</type>
 <description>this is a test item</description>
 <price>499.99</price>
 <categories>
  <value>18</value>
 </categories>
 <availability>available</availability>
 <weight>0.5</weight>
</product>

Upvotes: 0

Related Questions