Skip to main content
Solved

Getting Custom Fields using API

  • Jan 24, 2025 4:25 PM UTC
  • 6 replies
  • 471 views

Forum|alt.badge.img+2

I currently use a POST:

URL: api/v1.0/assets

with a json body of:

{"Filters":[{"Facet": "AssetSerialNumber","Value": "<asset-serial>"}]}

This works great. I am now trying to get and update the custom field we have which I can see in the response from above:

      "CustomFieldValues": [
{
"CustomFieldTypeId": "long_id_that_im_not_sure_if_i_should_post",
"EditorTypeId": 1,
"Value": "my value",
"IsHidden": false
},
],

I’ve tried doing: https://demo.iiqstaging.com/api/v1.0/custom-fields with json value:

{"Filters":[{"Facet": "AssetSerialNumber","Value": "<asset-serial>"}]}

But this does not work 

 

I am just wanting to get an Asset by its AssetSerialNumber value and then get its CustomField. I’d like to be able to get it and then update it possibility if I need to make changes.

Best answer by SPenland 4671c29 gilmer

With jclark’s help I was able to get custom fields working using the following example he provided:

var data = JSON.stringify({
"AssetIds":[
"{AssetId}"
],
"Request":{
"Values":[{
"Key":"$assets.custom-field:{CustomFieldTypeId}",
"Value":"{whatever you want your custom field value to be}"
}]
}
});
var url = "https://{yoursite}.incidentiq.com/api/v1.0/assets/bulk/set-info";
var options = {
method: 'POST',
headers: {
"SiteId": "{SiteId}",
"Authorization": "Bearer {your api token}",
"Pragma": "no-cache",
"Accept": "application/json, text/plain, */*",
"Client": "WebBrowser",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json",
},
redirect: 'follow',
muteHttpExceptions: false,
payload: data
};

Thank you so much!

View original

6 replies

Forum|alt.badge.img+17
  • Specialist
  • Jan 24, 2025 6:27 PM UTC

You should just be able to parse your response from the first call, change the field values you want in that, and send the entire (modified) response back in a POST to api/v1.0/assets


Kathryn Carter
Forum|alt.badge.img+18

​@SPenland 4671c29 gilmer Thank you for submitting your question to our community! 😄

As always ​@jclark is on it! Thanks! 


Forum|alt.badge.img+2

You should just be able to parse your response from the first call, change the field values you want in that, and send the entire (modified) response back in a POST to api/v1.0/assets

I have tried that now. I was able to get the fields out which is good. I simply replaced the text and tried posting back and I get not error but the fields do not change. Is there an email I can send you by response vs update posts?


bclark
Mentor
Forum|alt.badge.img+14
  • Mentor
  • Jan 30, 2025 6:15 PM UTC

You probably have to reference the Asset UUID number as well. Usually in the json it’s assetId I believe.


Forum|alt.badge.img+17
  • Specialist
  • Jan 30, 2025 6:52 PM UTC

Good call ​@bclark that was my mistake.
Post your payload back to api/v1.0/assets/{AssetId}


Forum|alt.badge.img+2

With jclark’s help I was able to get custom fields working using the following example he provided:

var data = JSON.stringify({
"AssetIds":[
"{AssetId}"
],
"Request":{
"Values":[{
"Key":"$assets.custom-field:{CustomFieldTypeId}",
"Value":"{whatever you want your custom field value to be}"
}]
}
});
var url = "https://{yoursite}.incidentiq.com/api/v1.0/assets/bulk/set-info";
var options = {
method: 'POST',
headers: {
"SiteId": "{SiteId}",
"Authorization": "Bearer {your api token}",
"Pragma": "no-cache",
"Accept": "application/json, text/plain, */*",
"Client": "WebBrowser",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json",
},
redirect: 'follow',
muteHttpExceptions: false,
payload: data
};

Thank you so much!