Update custom fields via API

Hi there,

I've been struggling to update custom fields using the API (via your Python package).

The most similar problem I can find reported is https://support.insight.ly/hc/en-us/community/posts/222741027-Update-CustomFields-api 

I have successfully read my custom field data, and updated standard fields, but when I try to update custom fields I get an HTTP 400 error.

It seems to be making 2 PUT requests, the first of which succeeds and the second of which fails.

Cheers,
Tom

0

Comments

12 comments
  • Have you tried using the API v2.2 to update custom field?  Each "main" entity has its own UpdateCustomField function.

    https://api.insight.ly/v2.2/Help#!/Contacts/UpdateCustomField

    0
    Comment actions Permalink
  • Hello Engineering team,

    Thanks for coming back promptly with this suggestion.

    Apologies, I'm afraid this was my fault. I was violating our own validation rules for the custom field - works as expected now I'm putting valid data.

    Best wishes,
    Tom

    0
    Comment actions Permalink
  • I'm trying to use the API to create/update a contact with custom fields. I'm sending them up as described in the API docs:

    CUSTOMFIELDS : [{

      CUSTOM_FIELD_ID : 'Total Spend',

      FIELD_VALUE : 200

    ]}

    but they aren't being added to the contact and I can't figure out why. Do the custom fields need to be setup beforehand?

    0
    Comment actions Permalink
  • Hi Tim,

    We're sorry to hear you're having issues with the API. When adding contacts with custom field information or updating custom fields, the custom fields and their values need to be added to Insightly beforehand. That means the custom fields and their values need to be created in Insightly before you can update or create that information in Insightly. To learn more about custom fields, we have information here: How to create custom fields.

    Also, when we reviewed your API code, we noticed that the format is a little off. Can you try using this code instead?

    CUSTOMFIELDS : [

    {
    CUSTOM_FIELD_ID : "Total Spend",

    FIELD_VALUE : 200
    }

    ]

    You had the array first before closing the custom field bracket.

    0
    Comment actions Permalink
  • Hi Alanna,

     

    Thanks for the help but I'm still running into issues.

     

    Here's my custom field:

     

    and here's what I'm sending through the API:

     

    CUSTOMFIELDS: [{
       CUSTOM_FIELD_ID: 'Total_Spend_c',
       FIELD_VALUE: stats.totalSpend
    }]

     

    I've tried a bunch of different things. Like for instance the API returns customer fields with the property FIELD_NAME, so I've tried this too:

    CUSTOMFIELDS: [{
       FIELD_NAME: 'Total_Spend_c',
       FIELD_VALUE: stats.totalSpend
    }]

     

    but that doesn't seem to work either. Any help would be awesome!

     

    0
    Comment actions Permalink
  • In my experience the CUSTOM_FIELD_ID is not the descriptive name that you give it in the Insightly GUI, but a generic ID like CONTACT_FIELD_2. The only way I identified which field was which in our case was to pull down some records via the API and look at the structure of the data that came back.

    Try filling in a single record manually and seeing if you can read that back by the API and you should discover which field ID you need...

    0
    Comment actions Permalink
  • Yea so when I do a GET request to get a contact I can see the custom fields I've already set on that contact:

     

    "CUSTOMFIELDS": [ {

        "FIELD_NAME": "Venues_Visited__c",

         "FIELD_VALUE": null },

    {

        "FIELD_NAME": "Total_Spend__c",

         "FIELD_VALUE": 200

    }]

     

    It's not at all clear in the API docs what the key should be when sending up custom fields (either a POST /contacts or a PUT to /contacts), so I've tried sending all these different variations

    1) FIELD_NAME key = "Total_Spend_C"

    2) CUSTOM_FIELD_ID key = "Total_Spent_C"

    3) FIELD_NAME key = "Total Spend"

    4) CUSTOM_FIELD_ID key = "Total Spend"

     

    The API docs are not very helpful and the API does not return any kind of errors messages or useful information.

    0
    Comment actions Permalink
  • Hmm, I don't get the descriptive field name when I GET records from the API, only the ID - which is also what I need to specify when I'm PUTting the data back to it. Weird. I've been using the Python library, maybe that's why we're seeing different behaviour...

    0
    Comment actions Permalink
  • The response I posted is what I'm getting when using their API docs to make the request:

    https://api.insightly.com/v3.0/Help#!/Contacts/GetEntity

     

    0
    Comment actions Permalink
  • Hi Tim,

    The correct way to add custom fields with v3.0 of the API is as follows:

    CUSTOMFIELDS: [{
       FIELD_NAME: 'Total_Spend__c',
       FIELD_VALUE: stats.totalSpend
    }]

    Please make sure the FIELD_NAME matches the value in the "Field name" column under System Settings => Objects and Fields.

    Let me know if you have any further questions

    0
    Comment actions Permalink
  • Thanks Brian,

    I've been trying that syntaxt and I'm still getting the error:

    Invalid field name 'Total_Spend_c'

    I've also tried changing the FIELD_NAME to 'Total Spend' and I get the same error.

    0
    Comment actions Permalink
  • You might be missing an underscore _ there, since all new custom fields have "__c" at the end of the name (2 underscores + c).

    0
    Comment actions Permalink

Please sign in to leave a comment.