Update CustomFields api

I'm trying to update custom fields but get an error message that I'm not really sure what they are asking for or where to put apiCustomField.

[{"Name":"apiCustomField","Message":"The parameter is required as a part of the request body"}]

Here is my data:

$data = array(
   "CUSTOM_FIELD_ID" => 'CONTACT_FIELD_2',
   "FIELD_VALUE" => 'data'
);

$service_url = "https://api.insight.ly/v2.2/contacts/{CustomerID}/CustomFields";

$ch = curl_init($service_url);
curl_setopt($ch,
CURLOPT_HTTPHEADER,
array('Content-Type: application/json',
'Authorization: Basic ' . base64_encode('{My-API-KEY}')));

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$return = curl_exec($ch);
$err = curl_errno($ch);
$msg = curl_error($ch);

curl_close($ch);

This is a similar issue (apiCustomField, but it didnt help: https://support.insight.ly/hc/en-us/community/posts/208147558-Custom-Field-PUT-not-working

I tried to get it to work in postman, but I just get {"Message":"Authorization has been denied for this request."}. I used basic Auth with Base64 encoded api key. The one thing I noticed is that postman adds "==" at the end of the base64. I keep trying to delete it but it just keeps it. So not sure what I am doing wrong.

0

Comments

5 comments
  • Hello Pablo,

    You are getting that error message as the API is expecting to receive parameter named "apiCustomField" in the request body. You can find the details about this particular call here: https://api.insight.ly/v2.2/help#!/Contacts/UpdateCustomField

    For using Postman, please look at the Authentication section under this post: https://support.insight.ly/hc/en-us/articles/204061444-Working-with-the-Insightly-Web-API. If you're seeing "==" at the end of the key, you do not need to update it. That's just the way it is encoding the key.

    Hope this helps! Please let us know if you have further questions.

    0
    Comment actions Permalink
  • Hello Pablo,

    Looking into it further, I don't think you'd need to pass in "apiCustomField" parameter to the body. You can simply pass the JSON object as 

    {
    "CUSTOM_FIELD_ID":"CONTACT_FIELD_2",
    "FIELD_VALUE":"some value"
    }

    I'd recommend trying it out in Postman and see if you are getting 200. 

    0
    Comment actions Permalink
  • Sorry, I really am missing how it wants me to send it. I read the error message [{"Name":"apiCustomField","Message":"The parameter is required as a part of the request body"}] which I included in my first post. It specifically tells me that it needs it as part of the request body. What I am asking is how does it want it? In what form? Where? I included my data to receive help. Please let me know how you want me to structure my data I send, this is what I have:

     

    $data = array(
       "CUSTOM_FIELD_ID" => 'CONTACT_FIELD_2',
       "FIELD_VALUE" => 'data'
    );

    Do I include 'apiCustomField' in the array? Where do you want me to include 'apiCustomField' 

    https://api.insight.ly/v2.2/help#!/Contacts/UpdateCustomField -> this is the page I got your api from. Its not very helpful and I've found it easier to get my answers from other people with the same issues. Unfortunately I didn't find one with my specific problem.

     

    As For Postman, that page was one I read but all it said was that I should use postman. So I still dont know how to get it set up with your API. I put the URL in, I added the basic authentication and I made sure it was json. It just says: Authorization has been denied for this request. So my guess is it didn't like how I set up the authentication although there isn't too many ways to get it wrong on Postman, its fairly straightforward so I was hoping there was something else I was missing.

    0
    Comment actions Permalink
  • Interesting.. It just updated with your response. If it doesn't require it, why is it asking for it?

    I tried submitting it and that's the error I get

    0
    Comment actions Permalink
  • For Postman, you can try passing in your API key (without encoding) as Username under the Authorization tab. Postman will automatically do the encoding for you and add it to the header. You can leave the password field empty.

    0
    Comment actions Permalink

Please sign in to leave a comment.