Deal details GET request custom field label instead of id in payload

I’ve done a get request for the details of a deal to return specific custom fields. I’m linking this to google sheets. Several of my custom fields I need are multiple dropdown type fields. The request just shows the id number but I need the label name.

e.g. “c4ecbe01c3494d1be52432f4a3194ede3a50c0f8”: “28” - where 28 is the id - but the information I need is the label " The name of this custom field is Lead Type. 28 represents ‘Expired’, which I can see when I go pull all deal fields and go and find that specific field.

"options": [
{
"label": "Expired",
"id": 28
},

It looks like the label ‘Expired’ is not included in the deal payload. So how do I change my request to return label output for deal details if a custom field has an id?

1 Like

See this Label Numbers vs labels

1 Like

Thanks for the reply. I did manage to download the get dealfields and then using the key and returned id loop through data and options to return the label. But I’m still struggling how to easily map back the label. And as I have about 10-15 custom fields with labels does this mean I have to loop through the whole dealfields json for each one just to return the appropriate label?

// Get deal data
  var dealurl = URL +'/v1/deals/' + dealId + '?api_token='+ API_TOKEN;
  var options = {
    "method": "get",    
    "contentType": "application/json",
  };
  var dealresponse = UrlFetchApp.fetch(dealurl, options);
  dealresponse = JSON.parse(dealresponse.getContentText());

  
 
  var propertyAddress = dealresponse.data["9bd1d8c4f07f5795fd8bffb16f3b63c6547d7d3a"];
  var leadType = dealresponse.data["c4ecbe01c3494d1be52432f4a3194ede3a50c0f8"];
      
  var dealType = dealresponse.data["a4269fb4730cf7fd1787752be94eacbc4b0de24e"];
  var dealSource = dealresponse.data["d76fa2d6f8454a51f7d64d981cd9320877bc2ea0"];

  
const obj = {
  "c4ecbe01c34994ede3a50c0f8": {id: 28},
  "a4269fb4730cf7fd1787752be94eacbc4b0de24e": {id: 37}
};  // Please set the key and id you want to search.
  
const dealFieldsresponse = {
  "success": true,
  "data": [
    {
      "id": 12500,
      "key": "c4ecbe01c34994ede3a50c0f8",
      "name": "Lead Type",
      "options": [
        {
          "label": "Expired",
          "id": 28
        },
        {
          "label": "Sale",
          "id": 29
        },
        {
          "label": "Rent",
          "id": 30
        },
        {
          "label": "Other",
          "id": 31
        }
      ],
      "mandatory_flag": false
    }
  ]
};

dealFieldsresponse.data.forEach(({key, options}) => {
  if (obj[key]) {
    options.forEach(({id, label}) => {
      if (id == obj[key].id) obj[key].label = label;
    });
  }
});
console.log(obj)