<?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: Bad Request with simple, bodyless GET request in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Bad-Request-with-simple-bodyless-GET-request/m-p/985041#M74065</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/600153"&gt;@GJakobTriad&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try with the below code&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) =&amp;gt; {

  // Make sure to add your API key under "Secrets" above.
  const hubspotClient = new hubspot.Client({
    accessToken: process.env.TicketConvoControl
  });

  const hubspot = require('@hubspot/api-client');

const hubspotClient = new hubspot.Client({"accessToken":"YOUR_ACCESS_TOKEN"});

const objectType = "tickets";
const objectId = event.object.objectId;
const toObjectType = "conversations";
const after = undefined;
const limit = 1;

try {
  const apiResponse = await hubspotClient.crm.associations.v4.basicApi.getPage(objectType, objectId, toObjectType, after, limit);
  console.log(JSON.stringify(apiResponse, null, 2));
} catch (e) {
  e.message === 'HTTP request failed'
    ? console.error(JSON.stringify(e.response, null, 2))
    : console.error(e)
}
// (code continues, but this first request fails)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"I hope this will help you out. Please mark it as &lt;STRONG&gt;Solution Accepted and upvote&lt;/STRONG&gt; to help another Community member.&lt;BR /&gt;Thanks!"&lt;/P&gt;</description>
    <pubDate>Fri, 31 May 2024 08:21:53 GMT</pubDate>
    <dc:creator>GRajput</dc:creator>
    <dc:date>2024-05-31T08:21:53Z</dc:date>
    <item>
      <title>Bad Request with simple, bodyless GET request</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Bad-Request-with-simple-bodyless-GET-request/m-p/984794#M74055</link>
      <description>&lt;P&gt;Trying to come up with a workflow custom code action, and this one starts off pretty simple, but for some reason it returns a 400 error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) =&amp;gt; {

  // Make sure to add your API key under "Secrets" above.
  const hubspotClient = new hubspot.Client({
    accessToken: process.env.TicketConvoControl
  });

  const searchResults = await hubspotClient
    .apiRequest({
      method: 'GET',
      headers: {
        authorization: `Bearer ${process.env.TicketConvoControl}`
      },
      path: `/crm/v4/objects/tickets/${event.object.objectId}/associations/conversations?limit=1`
  });

// (code continues, but this first request fails)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first thing I did before even getting to the custom code action is test on Postman with a simple cURL, which works without issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;curl --location 'https://api.hubapi.com/crm/v4/objects/tickets/1234567890/associations/conversations?limit=1' \
--header 'Authorization: Bearer EXAMPLETOKEN'&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 30 May 2024 19:15:12 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Bad-Request-with-simple-bodyless-GET-request/m-p/984794#M74055</guid>
      <dc:creator>GJakobTriad</dc:creator>
      <dc:date>2024-05-30T19:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Bad Request with simple, bodyless GET request</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Bad-Request-with-simple-bodyless-GET-request/m-p/985041#M74065</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/600153"&gt;@GJakobTriad&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try with the below code&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) =&amp;gt; {

  // Make sure to add your API key under "Secrets" above.
  const hubspotClient = new hubspot.Client({
    accessToken: process.env.TicketConvoControl
  });

  const hubspot = require('@hubspot/api-client');

const hubspotClient = new hubspot.Client({"accessToken":"YOUR_ACCESS_TOKEN"});

const objectType = "tickets";
const objectId = event.object.objectId;
const toObjectType = "conversations";
const after = undefined;
const limit = 1;

try {
  const apiResponse = await hubspotClient.crm.associations.v4.basicApi.getPage(objectType, objectId, toObjectType, after, limit);
  console.log(JSON.stringify(apiResponse, null, 2));
} catch (e) {
  e.message === 'HTTP request failed'
    ? console.error(JSON.stringify(e.response, null, 2))
    : console.error(e)
}
// (code continues, but this first request fails)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"I hope this will help you out. Please mark it as &lt;STRONG&gt;Solution Accepted and upvote&lt;/STRONG&gt; to help another Community member.&lt;BR /&gt;Thanks!"&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 08:21:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Bad-Request-with-simple-bodyless-GET-request/m-p/985041#M74065</guid>
      <dc:creator>GRajput</dc:creator>
      <dc:date>2024-05-31T08:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Bad Request with simple, bodyless GET request</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Bad-Request-with-simple-bodyless-GET-request/m-p/985381#M74071</link>
      <description>&lt;P&gt;Actually the issue was that I was sending the authentication twice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First one was implied here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const hubspotClient = new hubspot.Client({
    accessToken: process.env.TicketConvoControl
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So sending it as a header for&amp;nbsp;&lt;STRONG&gt;searchResults&lt;/STRONG&gt; was redundant and caused the 400 error.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 18:33:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Bad-Request-with-simple-bodyless-GET-request/m-p/985381#M74071</guid>
      <dc:creator>GJakobTriad</dc:creator>
      <dc:date>2024-05-31T18:33:40Z</dc:date>
    </item>
  </channel>
</rss>

