<?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: Parsing Axios response from an API call in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725559#M59285</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/314097"&gt;@PAtlan&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for the question. Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/338029"&gt;@LMartinez7&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/401263"&gt;@LeeBartelme&lt;/a&gt;, do&amp;nbsp;you have any suggestions for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/314097"&gt;@PAtlan&lt;/a&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Jaycee&lt;/P&gt;</description>
    <pubDate>Thu, 01 Dec 2022 20:33:26 GMT</pubDate>
    <dc:creator>Jaycee_Lewis</dc:creator>
    <dc:date>2022-12-01T20:33:26Z</dc:date>
    <item>
      <title>Parsing Axios response from an API call</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725313#M59247</link>
      <description>&lt;P&gt;I'm trying to get some information from a contact in custom code for a workflow.&lt;/P&gt;&lt;P&gt;I've set up a local environment to test my code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use fetch, I can access my HubSpot portal and get the information I need.&lt;/P&gt;&lt;P&gt;If I use the same route with Axios, the data I get is gibberish.&lt;/P&gt;&lt;P&gt;Here's a code sample:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;const axios = require('axios')

const objectType = "contact"
const toObjectType = "site"
const route = `/crm/v3/objects/${objectType}/${contactID}/associations/${toObjectType}`;
axios.defaults.baseURL = 'https://api.hubapi.com';
axios.defaults.headers.common['Authorization'] = 'Bearer XXXXXXXXXXXXXXXXXXXXXXXX';


let config = {
  method: 'get',
  url: '/crm/v3/objects/contact/474379/associations/site',
};

axios(config)
.then(function (response) {
  console.log(response.data)
  let ctype = response.headers["content-type"];
  console.log(ctype);
})
.catch(function (error) {
  console.log(error);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This returns :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;!� �RY�0~�f����/7��@V�9������zBq1{�,�����ή/�Pn�
application/json;charset=utf-8&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The same route, with the same Authorization, using fetch, returns:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{ results: [ { id: '491582160', type: 'site_to_contact' } ] }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm really not sure what I'm doing wrong. And because I can't seem to use fetch in a Hubspot Workflow code block, I really need to figure it out.&lt;/P&gt;&lt;P&gt;Thanks !&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 13:02:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725313#M59247</guid>
      <dc:creator>PAtlan</dc:creator>
      <dc:date>2022-12-01T13:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Axios response from an API call</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725559#M59285</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/314097"&gt;@PAtlan&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for the question. Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/338029"&gt;@LMartinez7&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/401263"&gt;@LeeBartelme&lt;/a&gt;, do&amp;nbsp;you have any suggestions for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/314097"&gt;@PAtlan&lt;/a&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Jaycee&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 20:33:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725559#M59285</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2022-12-01T20:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Axios response from an API call</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725567#M59287</link>
      <description>&lt;P&gt;Try setting the "Accept" headers to "application/json".&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 20:48:50 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725567#M59287</guid>
      <dc:creator>LeeBartelme</dc:creator>
      <dc:date>2022-12-01T20:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Axios response from an API call</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725576#M59288</link>
      <description>&lt;P&gt;Thanks for your reply, but no joy.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 21:13:05 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725576#M59288</guid>
      <dc:creator>PAtlan</dc:creator>
      <dc:date>2022-12-01T21:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Axios response from an API call</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725831#M59320</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/314097"&gt;@PAtlan&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't seem to replicate what you are seeing. For instance with the below code in a custom coded workflow action where 2-106192594 is the custom object schema ID for "Orders" in my test portal:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const axios = require('axios')

exports.main = async (event, callback) =&amp;gt; {

axios.defaults.baseURL = 'https://api.hubapi.com';
axios.defaults.headers.common['Authorization'] = 'Bearer ' + process.env.ACCESS_TOKEN;

let config = {
  method: 'get',
  url: '/crm/v3/objects/contact/151/associations/2-106182594'
};

axios(config)
.then(function (response) {
  console.log(response.data)
  let ctype = response.headers["content-type"];
  console.log(ctype);
})
.catch(function (error) {
  console.log(error);
});
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get the following response:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;results: [
    { id: '267226578', type: 'order_to_contact' },
    { id: '267234515', type: 'order_to_contact' }
  ]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also can you link to the documentation for the endpoint you have included within your example? I'm not able to find it on the developer docs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 12:53:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725831#M59320</guid>
      <dc:creator>coldrickjack</dc:creator>
      <dc:date>2022-12-02T12:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Axios response from an API call</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725858#M59323</link>
      <description>&lt;P&gt;Did you try running this code in an isolated workflow action without other code or logic, or is your provided example part of a larger code block? On the surface there really isn't any reason your result should be coming back that way as far as I can tell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's odd to me is "response.data" should contain a large JSON object that isn't unique to HubSpot. It should be Axios' standard response object. So your code resulting in what you posted tells me either there is some other logic outside of what you shared acting on the Axios object, or HubSpot was/is having some underlying issue when you were working on this. I don't see how it would have anything to do with the API itself.&lt;INPUT id="hippowiz-ass-injected" type="hidden" value="true" /&gt;&lt;INPUT id="hvmessage-toextension-listener" type="hidden" value="none" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 14:02:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Parsing-Axios-response-from-an-API-call/m-p/725858#M59323</guid>
      <dc:creator>LeeBartelme</dc:creator>
      <dc:date>2022-12-02T14:02:44Z</dc:date>
    </item>
  </channel>
</rss>

