DealStage Label name is required instead of internal name

I am using an API call to fetch the field values for deal but for dealstage instead of the label its giving me internal name.

Below is the API and other details.

API: https://api.hubapi.com/crm/v3/objects/deals/search

Payload:

{

“properties”: [

“hs_object_id”,

“dealname”,

“dealstage”,

],

“filterGroups”: [

{

“filters”: [

{

“propertyName”: “createdate”,

“operator”: “GTE”,

“value”: “2024-03-26T10:53:25Z”

}

]

}

]

}

Hi @MSrivastava1 :waving_hand:

Yeah it’s a real pain, but I can see why it’s been structured this way.
Anyway, I’d be tempted to add in a second step and use the pipelines API to pull the internal ID and DealStage value pair JSON, then iterate through them to find your label match.

Maybe something like this:

const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) => {

 const hubspotClient = new hubspot.Client({"accessToken":"YOUR ACCESS TOKEN HERE"});

 const dealStageInternal = event.inputFields['dealstage'];
 let dealStageLabel = ""; 

const objectType = "deal";
const pipelineId = "PUT THE ID OF YOUR PIPELINE";

try {
 const apiResponse = await hubspotClient.crm.pipelines.pipelineStagesApi.getAll(objectType, pipelineId);

for (let i = 0; i < apiResponse.results.length; i++) {
 console.log(`Checking id: ${apiResponse.results[i].id} against dealStageInternal: ${dealStageInternal}`);

 if (apiResponse.results[i].id == dealStageInternal) {
 dealStageLabel = apiResponse.results[i].label;
 console.log(`Match found: ${dealStageLabel}`);
 break; 
 }
}

if (!dealStageLabel) {
 console.log("No matching deal stage found.");
}

} catch (e) {
 e.message === 'HTTP request failed'
 ? console.error(JSON.stringify(e.response, null, 2))
 : console.error(e)
}

console.log(dealStageLabel); // Logs the label of the matching deal stage

 callback({
 outputFields: {
 email: email,
 dealStageLabel: dealStageLabel
 }
 });
}

Think it works, let me know how you get on :+1:

Hey, @MSrivastava1 :waving_hand: The endpoint will always return the internal value and not the label. The solution @EddBrisley suggested is a great approach to consider.

Best,

Jaycee