cerebrate icon indicating copy to clipboard operation
cerebrate copied to clipboard

Edit MetaFields via API

Open DocArmoryTech opened this issue 1 year ago • 1 comments

Hi,

I've been trying to work out how to edit an individual's "mobile_phone" field from the "CSIRT Network individual fields" (v2).

Is it possible to create or set a metaField using the API

DocArmoryTech avatar Aug 18 '22 21:08 DocArmoryTech

I think I've worked this out now...

I inspected the headers and payload used to set a MetaTemplate field in the browser; observing something like:

email: [email protected]
uuid: d157df4b-0554-419c-868f-01dda1c8ce8a
first_name: fred
last_name: flintstone
position: 
tag_list: 
MetaTemplates[1][meta_template_fields][1][metaFields][new][0]: 
MetaTemplates[1][meta_template_fields][2][metaFields][new][0]: +353871234567
MetaTemplates[1][meta_template_fields][3][metaFields][new][0]: 
MetaTemplates[1][meta_template_fields][4][metaFields][new][0]: 
MetaTemplates[1][meta_template_fields][5][metaFields][new][0]: 
MetaTemplates[1][meta_template_fields][6][metaFields][new][0]: 
MetaTemplates[1][meta_template_fields][7][metaFields][new][0]: 
MetaTemplates[1][meta_template_fields][8][metaFields][new][0]: 
MetaTemplates[1][meta_template_fields][9][metaFields][new][0]:

I ?mistakenly? took this as a cue to update via the API using a json equivalent of the above. I was unsuccessful in this approach.

I instead found updating the top-level Individual attribute named meta_fields achieved the desired result using the API. e.g. to update the first_name, last_name and mobile_phone of individual with email: [email protected] and an id of 8

{
    "id":8,
    "email":"[email protected]",
    "first_name":"fred",
    "last_name":"flintstone",
    "meta_fields": [
        {
            "scope": "individual",
            "parent_id": 8,
            "field": "mobile_phone",
            "value": "+333333333333",
            "uuid": "df8c35ad-ded9-48e0-a286-da318b757868",
            "meta_template_id": 1,
            "meta_template_field_id": 2
        }
    ]
}

DocArmoryTech avatar Aug 19 '22 13:08 DocArmoryTech