I am getting this error when trying to call Post Contacts endpoint:
{\r\n "ErrorNumber": 14,\r\n "Type": "PostDataInvalidException",\r\n "Message": "Invalid Json data"\r\n}
This is my JSON:
{
"Contacts": [
{
"Name": "Delia Du Toit",
"ContactNumber": "2010080871087",
"AccountNumber": "2222",
"ContactStatus": "ACTIVE",
"FirstName": "Delia",
"LastName": "Du Toit",
"CompanyNumber": "123456789",
"EmailAddress": "myemail@gmail.com",
"SkypeUserName": "",
"Addresses": [
{
"AddressType": "STREET",
"AddressLine1": "1 Du Bois",
"AddressLine2": " ",
"AddressLine3": "",
"AddressLine4": "",
"City": "Brakpan",
"PostalCode": "1540",
"Country": "South Africa",
"Region": "Gauteng"
},
{
"AddressType": "POBOX",
"AddressLine1": "",
"AddressLine2": "",
"AddressLine3": "",
"AddressLine4": "",
"City": "",
"PostalCode": "",
"Country": "",
"Region": ""
}
],
"Phones": [
{
"PhoneType": "DDI",
"PhoneNumber": " 011 852 2589",
"PhoneAreaCode": "",
"PhoneCountryCode": "+27"
}
],
"IsCustomer": true,
"DefaultCurrency": "ZAR"
}
]
}
This is my function:
public static async Task<string> SaveContact(string tenant_id, string contact)
{
string result = "";
string url = "https://api.xero.com/api.xro/2.0/contacts";
string key = string.Format("Bearer {0}", Token);
var client = new RestClient(url);
var request = new RestRequest("/", Method.Post) { AlwaysMultipartFormData = true };
request.AddHeader("authorization", key);
request.AddHeader("Xero-tenant-id", tenant_id);
request.AddHeader("content-type", "application/json");
request.AddBody(contact, "application/json");
var response = await client.ExecuteAsync(request);
result = response.Content;
if(response.StatusCode == HttpStatusCode.OK)
{
return "OK";
}
return result;
}
Not sure what is wrong. Not sure where to start looking either since my Json appears correct and the error appears to be very generic? Could someone shed some light on this please?
Thanks