1

I am using the API to communicate batches of contacts using the endpoint /contacts/v1/contact/batch/

I get an error message response which reads@

{"status":"error", "message":"Invalid input JSON on line 1, column 1: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token","correlationId":"3c1488a8-24f5-4e1c-b506-18edcd870065","requestId":"a85c3ea88b60a7d0e3cfe5736c819b11"}

The JSON i am sending is valid. I've checked and double checked. Please help :(

My output is below

[
  {
    "email": "twst@email.com",
    "properties": [
  {
    "property": "company",
    "value": "Test"
  },
  {
    "property": "website",
    "value": "www.test.com"
  },
  {
    "property": "firstname",
    "value": "Carl"
  },
  {
    "property": "lastname",
    "value": "Swann"
  },
  {
    "property": "jobtitle",
    "value": "Dr"
  },
  {
    "property": "phone",
    "value": "0789654321"
  },
  {
    "property": "product",
    "value": "Khaos Control Hybrid"
  },
  {
    "property": "eventList_2019",
    "value": "Spring Fair"
  }
 ]
  },
   {
      "email": "email@yes .com",
       "properties": [
   {
       "property": "company",
       "value": "Another one"
    },
    {
       "property": "website",
       "value": "www.a.ither.com"
    },
    {
       "property": "firstname",
       "value": "Anither"
    },
    {
       "property": "lastname",
       "value": "One"
    },
    {
       "property": "jobtitle",
       "value": "Com"
    },
    {
       "property": "phone",
       "value": "0789675341"
    },
    {
       "property": "product",
       "value": "Khaos Control Hybrid"
    },
    {
       "property": "eventList_2019",
       "value": "Spring Fair"
    }
    ]
    },
    {
       "email": "keeley@sophieallport.com",
       "properties": [
    {
        "property": "company",
        "value": "Sophie Allport"
    },
    {
        "property": "website",
        "value": "www.sophieallport.com"
    },
    {
        "property": "firstname",
        "value": "Keeley"
    },
    { 
        "property": "lastname",
        "value": "Walters"
    },
    {
        "property": "jobtitle",
        "value": "Accounts "
    },
    {
        "property": "phone",
        "value": "01778235648"
    },
    {
        "property": "product",
        "value": "Khaos Control Hybrid"
    },
    { 
        "property": "eventList_2019",
        "value": "Spring Fair"
    }
    ]
  }
]
Swanne
  • 88
  • 9
  • Possible duplicate of [Can not deserialize instance of java.util.ArrayList out of VALUE\_STRING](https://stackoverflow.com/questions/14588727/can-not-deserialize-instance-of-java-util-arraylist-out-of-value-string) – tshimkus Mar 16 '19 at 14:24
  • Have you found the solution to your problem? I am getting the same error from hubspt. – Cave Johnson May 31 '19 at 21:45
  • Hey @KodosJohnson I did manage to get this working, it was something to do with the list of properties not being implemented as a new instance. It was quite a while ago so cant remember exactly. If you're still having this problem, drop me a line with sample code to swanne2@hotmail.co.uk – Swanne Jun 03 '19 at 14:53

1 Answers1

0

I found the source code I used and will try my best to explain my implementation of it for you.

The application I created was a mobile app that is used by companies to capture information about new prospects and send that information into their HubSpot account.

The main application contains a class of Prospect which defines the information we want to obtain about a prospect

public class Prospect
{
    public string CompanyName { get; set; }
    public string Website { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string JobTitle { get; set; }
    public string Phone { get; set; }
    public string Email { get; set; }
    public string Products { get; set; }
    public string Notes { get; set; }
    public string ContactOwner { get; set; }
    public string ShowName { get; set; }
}

The component of the application which is relevant to the question you asked contains 2 classes:

public class HubSpotProspect
{
    public string email { get; set; }
    public List<Property> properties { get; set; }
}


public class Property
{
    public string property { get; set; }
    public string value { get; set; }
}

The following code gets a list of all the prospects then iterates through them to assign the correct attribute values and translates then into a new list of HubSpotProspect. We then serialise this list into json and pass it to the function that communicates with HubSpot API.

List<Prospect> _pList = _prospectList.GetProspectList(ShowName);

List _hsProspectList = new List();

foreach (Prospect p in _pList)
{
    HubSpotProspect _hsp = new HubSpotProspect();
    _hsp.email = p.Email;
    _hsp.properties = new List<Property>();
    _hsp.properties.Add(new Property { property = "company", value = p.CompanyName });
    _hsp.properties.Add(new Property { property = "website", value = p.Website });
    _hsp.properties.Add(new Property { property = "firstname", value = p.FirstName });
    _hsp.properties.Add(new Property { property = "lastname", value = p.LastName });
    _hsp.properties.Add(new Property { property = "jobtitle", value = p.JobTitle });
    _hsp.properties.Add(new Property { property = "phone", value = p.Phone });
    _hsp.properties.Add(new Property { property = "product", value = p.Products });
     _hsp.properties.Add(new Property { property = "event_list_2019", value = p.ShowName });
    _hsp.properties.Add(new Property { property = "hubspot_owner_id", value = _userProfile.GetContactOwner() });

    _hsProspectList.Add(_hsp);
}

string json = JsonConvert.SerializeObject(_hsProspectList);
await SendContact(json);

The function that communicates with the HubSpot API is as follows:

private Task SendContact(string JsonString)
    {
        return Task.Factory.StartNew(() =>
        {
            string hapiKey = _userProfile.GetHapiKey();

            var client = new RestClient(https://api.hubapi.com/);
            var request = new RestRequest("contacts/v1/contact/batch/", Method.POST);
            request.AddQueryParameter("hapikey", hapiKey);
            request.RequestFormat = DataFormat.Json;
            request.AddJsonBody(JsonString);

            IRestResponse response = client.Execute<HubSpotProspect>(request);
            var content = response.Content;
            //Console.WriteLine("RESPONSE " + content);
        });
    }
Swanne
  • 88
  • 9