Creating Customer works fine, cannot update Contact Address via the API

drancourdrancour Posts: 8Member
edited November 2017 in Development
I am able to create a new customer via the API but I am unable to set the Contact address information using the API. After reviewing the API documentation I'm beginning to think the Contact address cannot be updated via the API.

Can you confirm if the Customer Contact address information can be updated via the API?

9 comments

  • jamesratcliffejamesratcliffe Posts: 160Administrator, Lightspeed Staff moderator
    You can set the contact info by including it as a sub-object, like this:
    {
    "firstName": "Joe",
    "lastName": "Customer",
    "Contact": {
    "custom": "Random Customer Info",
    "noEmail": "false",
    "noPhone": "true",
    "noMail": "false",
    "Addresses": {
    "ContactAddress": {
    "address1": "700 St-Antoine Est",
    "address2": "Suite 300",
    "city": "Montreal",
    "state": "QC",
    "zip": "H2Y 1A6",
    "country": "Canada"
    }
    },
    "Phones": {
    "ContactPhone": {
    "number": "866 932 1801",
    "useType": "Work"
    }
    },
    "Emails": {
    "ContactEmail": {
    "address": "[email protected]",
    "useType": "Primary"
    }
    },
    "Websites": {
    "ContactWebsite": {
    "url": "http://www.lightspeedhq.com"
    }
    }
    }
    }
    See also: http://developers.lightspeedhq.com/retail/introduction/relations/
    James Ratcliffe
    Lightspeed HQ
  • drancourdrancour Posts: 8Member
    Thanks James - I am using the XML end points. However I am not able to update the Contact information, I am getting "Bad Request" back. Can you see what I'm doing wrong? Here's an example (data anonymized):

    To the new customer end point:
    https://api.merchantos.com/API/Account/acctIdHere/Customer/11.xml
    <?xml version="1.0" encoding="utf-16"?>
    <Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <firstName />
      <lastName>A &amp; M</lastName>
      <title />
      <company>A &amp; M</company>
      <companyRegistrationNumber />
      <vatNumber />
      <creditAccountID>0</creditAccountID>
      <customerTypeID>2</customerTypeID>
      <discountID>0</discountID>
      <taxCategoryID>0</taxCategoryID>
      <customerID>11</customerID>
      <createTime>2017-11-04T17:08:19+00:00</createTime>
      <timeStamp>2017-11-04T17:08:19+00:00</timeStamp>
      <archived>false</archived>
      <Contact>
        <custom />
        <noEmail>false</noEmail>
        <noPhone>false</noPhone>
        <noMail>false</noMail>
        <Addresses>
          <ContactAddress>
            <address1>123 That Street</address1>
            <address2 />
            <city>Phoenix</city>
            <state>AZ</state>
            <zip>12345</zip>
            <country>USA</country>
          </ContactAddress>
        </Addresses>
        <Phones />
        <Emails />
        <Websites />
        <timeStamp>2017-11-04T17:08:19+00:00</timeStamp>
      </Contact>
    </Customer>
    
  • jamesratcliffejamesratcliffe Posts: 160Administrator, Lightspeed Staff moderator
    You should check the response body. It will indicate that you're specifying an invalid text encoding. Use "utf-8" instead.
    James Ratcliffe
    Lightspeed HQ
  • drancourdrancour Posts: 8Member
    That's got it! Thank you James!!
  • jamesratcliffejamesratcliffe Posts: 160Administrator, Lightspeed Staff moderator
    You're welcome
    James Ratcliffe
    Lightspeed HQ
  • drancourdrancour Posts: 8Member
    Hey James - one more question related to this, is it possible to create a new customer with all the contact information in 1 call? Basically I'm having to do a POST to create the new customer with the company name/last name, then do a PUT to update with the contact information. Due to the rate limiting, this costs 20 units per customer - my customers' bucket is only 60 units so processing 100 customers takes ~30 minutes. If I could do this in 1 call I could double my processing, but when I tried to send the whole new object I get 422 - Unprocessable Entity.

    Should it be possible to create the customer with all information in 1 call?
  • jamesratcliffejamesratcliffe Posts: 160Administrator, Lightspeed Staff moderator
    edited November 2017
    Yes, you just include all the contact information like I did in the example. If you're getting a 422 error, the response body will give you more details.
    Post edited by jamesratcliffe on
    James Ratcliffe
    Lightspeed HQ
  • drancourdrancour Posts: 8Member
    Thanks James - I see the problem, archive cannot be specified for create:

    Customer not Created. "archived" cannot be set on Create.
  • jamesratcliffejamesratcliffe Posts: 160Administrator, Lightspeed Staff moderator
    You’re welcome.

    You generally can't set the "archived" field directly. You have to use the DELETE method.
    James Ratcliffe
    Lightspeed HQ
Sign In or Register to comment.