How to create contact info for Vendor

mikesitmikesit Posts: 11Member
We need to create Vendors with contact info (name, address, phone, etc) via the API.  I cannot find anyway of doing this from the docs - https://developers.lightspeedhq.com/retail/endpoints/Vendor/.

The Vendor object has a Contact reference field but I can find no way (that works) to attach that info at Vendor Create (POST) time.

- rock


Best Answer

  • mikesitmikesit Posts: 11Member
    Accepted Answer
    UPDATE:

    We've determined that the API exhibits this behavior with multiple return types.  We don't have time to test them all of course; but the solution was to implement a customized JSON converter class.  That solves the issue.


Answers

  • Michael CareyMichael Carey Posts: 48Administrator, Lightspeed Staff moderator
    Hi @mikesit ,

    You can create a Vendor with contact information by including the Contact object on create.

    {
      "name": "Test Vendor",
      "Contact": {
        "noEmail": "false",
        "noPhone": "false",
        "noMail": "false",
        "Addresses": {
          "ContactAddress": {
            "address1": "500 King Street",
            "address2": "Suite 101",
            "city": "Montreal",
            "state": "QC",
            "zip": "H1H1H1",
            "country": "Canada",
            "countryCode": "",
            "stateCode": ""
          }
        },
        "Phones": {
          "ContactPhone": {
            "number": "123-456-7890",
            "useType": "Work"
          }
        },
        "Emails": "[email protected]",
        "Websites": "https://www.testvendor.com"
      }
    }
    
    Michael Carey
    API Integrations Specialist
    Lightspeed HQ
  • mikesitmikesit Posts: 11Member
    Thanks Mike,
    I'll give that a try today...  a few questions tho...

    1) I could not find the Contact object schema in the API docs, is it there and I missed it or is it an omission?

    2) I see in the Contact object you presented in your response, that the "Addresses" & "Phones" properties are plural.  Does this indicate that they may be arrays?  I have seen in your API before that when the API defines a List of objects but when the returned payload only contains a single object in that list, that the API returns a single JSON object syntax instead of the defined Array of objects containing only the single element.  We found this to be true for the Get ALL call on items.

    If that is true, Should I consider this standard behavior for all lists returned by the API?

    Regards,
    - rock








  • gregaricangregarican Posts: 58Member
    I ran into this quirk in a lot of API endpoints. I'd think that any property that _can_ contain an object array should always pass back the brackets [ ] even if a single object is returned. I'm no JSON expert, but I'd think the consistency would lead to less gotchas.

    My code is C# for interfacing with the LS Retail API. What I did was add the Newtonsoft.JSON library to my project and then I could handle this quirk by prefacing any class property like this:

    [JsonConverter(typeof(JsonHelper.SingleValueArrayConverter<YourProperty>))]

    That allowed by JSON converstion routines to handle this. Defining this in the model classes was easier than implementing a custom JSON converter all over the place!
  • mikesitmikesit Posts: 11Member
    Hey gregarican,

    I agree, the API should do this by default...

    We ended up doing exactly what you described.  All is well...

    - rock
Sign In or Register to comment.