APIs & Integrations

surajsironi
Miembro

Requesting help on GET : REST API (ServiceNow and Hubspot Deal)

Hi,

Someone help me in REST API.

Use Case : in Hub spot when deal stage = closedwon then create incident in servicenow

 
 

hubspot.png

ServiceNowScheduled Job :

alldeals();

function alldeals() {
    var r = new sn_ws.RESTMessageV2('Hubspot', 'AllDeals');

    var response = r.execute();
    var responseBody = response.getBody();
    var httpStatus = response.getStatusCode();
    var obj = JSON.parse(responseBody);
    
    var loop = obj.total;
	
    for (var i = 0; i <= loop; i++) 
	{
		
	gs.info('DealLoop 1');
        var dstage = obj.results[i].properties.dealstage.value;
        gs.info("DealStage :" + dstage);
    if (dstage == "closedwon") 
	{
	gs.info('DealLoop 2');

       var inc = new GlideRecord('incident');
       inc.addQuery('u_died', obj.results[i].dealId);
       inc.query();
       gs.log('Row count is ' + inc.getRowCount());
       if (!inc.next()) 
       {
	gs.info('DealLoop 3');

        inc.initialize();
        inc.short_description = obj.results[i].dealname;
        inc.u_died = obj.results[i].dealId;
        inc.insert();

            }
        }
    }
}

 

i don't why even i m not getting total number of Deals also by using below:

var loop = obj.total;

0 Me gusta
1 Respuesta 1
Derek_Gervais
Exmiembro de HubSpot
Exmiembro de HubSpot

Requesting help on GET : REST API (ServiceNow and Hubspot Deal)

Hey @surajsironi ,

 

I'm not really familiar with this code, or the libraries you're using, but there's no total field in the JSON returned by the "Get all deals" endpoint. You can see an example of the response JSON here: https://legacydocs.hubspot.com/docs/methods/deals/get-all-deals

0 Me gusta