Adding product filters and categories through the API

isparktoysisparktoys Posts: 4Member
We are trying to use the eCom API to add filters and categories to products in batch. We have not been successful so far on either attempt though. Here is what we do in Python using requests, and what we get as a response:

payload = {    "productFilterValue": {        "filter": 5010,        "filtervalue": 17975    }}

requests.post(url="https://api.shoplightspeed.com/us/products/15239803/filtervalues.json", auth=HTTPBasicAuth(API_KEY, API_SECRET), data=payload)



In response, we get a 403 back:

'{"error":{"code":403,"method":"CREATE","request":"\\/us\\/products\\/15239803\\/filtervalues.json",
  "message":"The server understood the request, but is refusing to fulfill it."}}'
We see the same behavior when we try the "categories/products" endpoint to attach a category to a product.

Other operations (reading product and category data, creating webhooks, etc.) work as expected, so I don't think this is a matter of authentication.

What am I doing wrong?

Answers

  • Michael CareyMichael Carey moderator Posts: 68Administrator, Lightspeed Staff moderator
    edited August 2018
    Hello,

    The first thing I noticed was the naming of the Product Filter Value object. The object should be named productFiltervalue (no upper case 'v'). 

    Secondly, you'll want to wrap your payload in single quotes as follows:

    payload = '{"productFiltervalue": {"filter": 5010,"filtervalue": 17975}}'

    Let me know if that works for you.

    Thanks,

    Michael Carey

    Product Manager
    Lightspeed HQ
  • isparktoysisparktoys Posts: 4Member
    edited August 2018
    Hi Michael;

    Thank you for your response. Unfortunately this did not turn out to be the solution. Here is what I have with your edits:
    auth = HTTPBasicAuth(api_key, api_secret)
    payload = '{"productFiltervalue": {"filter": 5010,"filtervalue": 17975}}'
    r = requests.post("https://api.shoplightspeed.com/us/products/15239803/filtervalues.json", data=payload, auth=auth)
    
    r.text
    '{"error":{"code":403,"method":"CREATE",
    "request":"\\/us\\/products\\/15239803\\/filtervalues.json",
    "message":"The server understood the request, but is refusing to fulfill it."}}'

    As I mentioned in my original question, the same thing happens when we try to add products to categories:

    payload = '{"categoriesProduct": {"category": 1162618,"product": 15239803}}'
    
    r = requests.post("https://api.shoplightspeed.com/us/categories/products.json", data=payload, auth=auth)
    
    r.json()
    {'error': {'code': 403,
      'method': 'CREATE',
      'request': '/us/categories/products.json',
      'message': 'The server understood the request, but is refusing to fulfill it.'}}
    Post edited by isparktoys on
  • Michael CareyMichael Carey moderator Posts: 68Administrator, Lightspeed Staff moderator
    Hello,

    I checked your account and realized that this error is in fact related to the permissions on the API key.

    Shops that have Omnichannel enabled cannot write to products via the eCom API. Only the Retail API allows for writing to products on Omnichannel shops. We should make this error message more clear.

    Thanks, 
    Michael Carey

    Product Manager
    Lightspeed HQ
  • isparktoysisparktoys Posts: 4Member
    Hi Michael;

    As retail API does not give access to product filters, how do you recommend we go about updating filters in batch?

    Same with multiple categories. As retail only allows a single category to be associated with a product, there is no way for us to set multiple categories through the retail API. How do you recommend that we set multiple categories on a product at the eCom side?

  • Michael CareyMichael Carey moderator Posts: 68Administrator, Lightspeed Staff moderator
    Hi,

    The only way to update filters (and categories) in batch is by doing a product import. You can read more about product imports here:

    https://ecom-support.lightspeedhq.com/hc/en-us/articles/220320628-Editing-products-through-import
    Michael Carey

    Product Manager
    Lightspeed HQ
  • isparktoysisparktoys Posts: 4Member
    Hi Michael;

    Maybe I’m reading this wrong, but it doesn’t seem to answer the question on multiple categories, as there seems to be only one category in the import template. 

    We were also told that the filter import feature doesn’t currently work, is it resolved now?
  • Michael CareyMichael Carey moderator Posts: 68Administrator, Lightspeed Staff moderator
    I'm not very familiar with the import tool but from what I understand it is currently working. 

    To import multiple categories you would need to do multiple imports. Each product import can add one set of categories: main, secondary,  tertiary. 

    I hope that helps answer your question. 
    Michael Carey

    Product Manager
    Lightspeed HQ
Sign In or Register to comment.