Problem with updating Item TagRelations.Tag

BillHuBillHu Member Posts: 3
Hello Everyone,

I am currently experiencing a problem with trying to update the tags of items through the API.

The query string is: "{"Tags": {"Tags": ["a", "b"]}}"

And the error returned is: "{'httpCode': '500', 'httpMessage': 'Internal Server Error', 'message': 'Can not convert an array to XML when array has numeric indexed values.', 'errorClass': 'Exception'}"

If I only put one tag in the query which looks like:  "{"Tags": {"Tags": "a"]}}", the update is successful. So as the error suggests, there is a problem with the array.

I have searched all the documentation but did not find an answer.

Please advise the correct way to update multiple tags or append tags to existing ones.

Thank you.
Tags:

5 comments

  • BillHuBillHu Member Posts: 3
    Please advise, thank you!
  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 654 moderator
    edited February 2019
    Hey @BillHu,

    There is a bug in our API that doesn't allow you to add multiple tags using a JSON formatted request. You have to enter it in via XML like this:

    Request URL:

    https://api.lightspeedapp.com/API/Account/{{accountID}}/Item/{{itemID}}

    Request Method: PUT
    Request Payload:

    <div><Item></div><div>&nbsp; &nbsp; <Tags></div><div>&nbsp; &nbsp; &nbsp; &nbsp; <tag>tag1</tag></div><div>&nbsp; &nbsp; &nbsp; &nbsp; <tag>tag2</tag></div><div>&nbsp; &nbsp; </Tags></div><div></Item></div>

    Hope this helps!
    Post edited by Adrian Samuel on

    Adrian Samuel

    Software Developer

    Lightspeed HQ

  • BillHuBillHu Member Posts: 3
    Using XML solved the problem.

    Thank you for the quick response!
  • QuinceyQuincey Member Posts: 5

    Has this bug been fixed?

    Also where did you find the documentation on where to add tags to an item?

  • Ali_MasoumieAli_Masoumie Moderator, Lightspeed Staff Posts: 346 moderator

    Hi @Quincey,

    Here is some more information on the tags:

    * If the product already has a tag an update will overwrite the existing tag(s),

    * Using JSON you can only create/update the item with one tag, and

    * For multiple tags creation/update you will need to use XML.


    Example JSON Payload:

    {
      "Tags" : {
        "tag" : "the_name_of_the_tag"
      }
    }
    


    Example XML Payload:

    <Item>
     <Tags>
      <tag>Tag1</tag>
      <tag>Tag2</tag>
     </Tags>
    </Item>
    

    Hope this helps.

Sign In or Register to comment.