We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Sep 1, 2020 5:53 PM
Hi,
Someone help me in REST API.
Use Case : in Hub spot when deal stage = closedwon then create incident in servicenow
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;
Sep 2, 2020 5:24 PM
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