All,
I'm trying to create a Contact via the REST API - that works without issues if I don't include custom boolean fields in the request. However, my Contact object contains a pair of custom boolean values:
isSystemUser__c
MaintenanceEmailOptedOut__c
Whenever I try to set these via Java REST POST commands, I end up with an HTTP 400.
In the workbench I can create these without issues. I set the request to POST, with a URL of /services/data/v36.0/sobjects/Contact and data as follows:
{"accountId":"001g000000myI4m","email":"test@test.com","hasOptedOutOfEmail":true,"MaintenanceEmailOptedOut__c":true,"firstName":"firstname","lastName":"lastname","phone":"123-456-7890","isSystemUser__c":false,"Role__c":"role"}
Similarly, in my Java Code, the creation succeeds if I only pass in the following fields (note that role is a custom string field but works without issues):
String json = "{\"AccountId\":\"001g000000myI4m\",\"Email\":\"test@test.com\",\"FirstName\":\"firstname\",\"LastName\":\"lastname\",\"Phone\":\"123-456-7890\",\"HasOptedOutOfEmail\":\"true\",\"Role__c\":\"dummyrole\"}";
StringEntity customerEntity = new StringEntity(json);
httpPost.addHeader("Content-Type","application/json; charset=UTF-8");
httpPost.addHeader("Accept", "application/json");
httpPost.setEntity(customerEntity);
HttpResponse response = httpClient.execute(httpPost);
However, as soon as I add the pair of custom boolean values, I get that pesky 400. Is there some different way of handling custom boolean attributes? I've verified that the API name for these fields is correct, and the fact that it works within workbench leads me to believe that the JSON is fine. I've tried passing in different values ("1"/"0" instead of "true"/false" for example) with no joy.
Can anyone lend any expertise here?
Thanks in advance!
PS
When I was swapping "1"/"0" I also tested true and false (without the quotes) and still get a 400. I've re-tested that again and have received the same result. My confusion stems mainly from the fact that I can set the HasOptedOutOfEmail
boolean property (a standard field) via the API, using a String value of "true" (with the quotes) but am unable to do the same for the custom field.
JSON.serialize
on a Contact in an execute anonymous window to see the format that the data is serialised into.