<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using fetch() instead of requests library in custom action? in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Using-fetch-instead-of-requests-library-in-custom-action/m-p/521103#M48412</link>
    <description>&lt;P&gt;Here's what I have at this point:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;const hubspot = require('@hubspot/api-client');&lt;/P&gt;&lt;P&gt;exports.main = (event, callback) =&amp;gt; {&lt;BR /&gt;let endresult = processEvent(event)&lt;BR /&gt;console.log(endresult)&lt;BR /&gt;return callback(endresult);&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;function processEvent(event) {&lt;/P&gt;&lt;P&gt;// secrets can be accessed via environment variables&lt;/P&gt;&lt;P&gt;const hubspotClient = new hubspot.Client({&lt;/P&gt;&lt;P&gt;apiKey: process.env.HAPIKEY&lt;/P&gt;&lt;P&gt;});&lt;/P&gt;&lt;P&gt;hubspotClient.crm.contacts.basicApi.getById(event["object"]["objectId"], ["email", "phone"])&lt;/P&gt;&lt;P&gt;.then(results =&amp;gt; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let companyName = results.body.properties.name;&lt;/P&gt;&lt;P&gt;let address = results.body.properties.address;&lt;/P&gt;&lt;P&gt;let state = results.body.properties.state_address;&lt;/P&gt;&lt;P&gt;let result = {}&lt;/P&gt;&lt;P&gt;function prediction() {&lt;/P&gt;&lt;P&gt;const url = '&lt;A href="https://apiv2.usemarvin.ai/naics/naics/search/additional" target="_blank"&gt;https://apiv2.usemarvin.ai/naics/naics/search/additional&lt;/A&gt;'&lt;/P&gt;&lt;P&gt;const data = {&lt;BR /&gt;"token": process.env.Relativity6_API_Key,&lt;BR /&gt;"name": companyName,&lt;BR /&gt;"address": address,&lt;BR /&gt;"state": state&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;fetch(url, {&lt;BR /&gt;method: 'POST',&lt;BR /&gt;headers: { 'Content-Type': 'application/json' },&lt;BR /&gt;body: JSON.stringify(data)&lt;BR /&gt;})&lt;BR /&gt;.then(resp =&amp;gt; {&lt;BR /&gt;return resp.json()&lt;BR /&gt;})&lt;BR /&gt;.then(res =&amp;gt;&lt;BR /&gt;console.log(res))&lt;BR /&gt;.catch(err =&amp;gt;&lt;BR /&gt;console.log(err)&lt;BR /&gt;)&lt;BR /&gt;}&lt;BR /&gt;result = prediction()&lt;BR /&gt;console.log(result)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;return {&lt;/P&gt;&lt;P&gt;outputFields: {&lt;/P&gt;&lt;P&gt;primary_naics_code: result.naics_prediction_a.naics_code,&lt;/P&gt;&lt;P&gt;primary_naics_description: result.naics_prediction_a.naics_title,&lt;/P&gt;&lt;P&gt;primary_naics_code_conf_score: result.naics_prediction_a.confidence_score,&lt;/P&gt;&lt;P&gt;primary_naics_code_last_rtrvl_date: result.response_timestamp,&lt;/P&gt;&lt;P&gt;primary_naics_code_update_source: "Relativity6",&lt;BR /&gt;secndary_naics_code_1: result.naics_prediction_b.naics_code,&lt;/P&gt;&lt;P&gt;secondary_naics_description_1: result.naics_prediction_b.naics_title,&lt;/P&gt;&lt;P&gt;secondary_naics_code_conf_score_1: result.naics_prediction_b.confidence_score,&lt;/P&gt;&lt;P&gt;secondary_naics_code_last_rtrvl_date_1: result.response_timestamp,&lt;/P&gt;&lt;P&gt;secondary_naics_code_update_source: "Relativity6"&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;})&lt;BR /&gt;.then(result =&amp;gt;{return result})&lt;BR /&gt;.catch(err =&amp;gt; {&lt;/P&gt;&lt;P&gt;console.error(err)&lt;/P&gt;&lt;P&gt;})&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have already separately checked the API, blaming that is no good. The problem is either in the Hubspot API library or the Hubspot custom code action environment. I can't see anything from console.log, either it's not available trough the workflow's history or the junk the environment spits out clogs some 4KB limit on output text when I test the code. Anyone got an idea what's wrong, here? I'm doing my best to imitate Hubspot's example code, but if it doesn't work for anything slightly more complex than the demos...&lt;/P&gt;</description>
    <pubDate>Thu, 04 Nov 2021 15:57:03 GMT</pubDate>
    <dc:creator>MMartin78</dc:creator>
    <dc:date>2021-11-04T15:57:03Z</dc:date>
  </channel>
</rss>

