# Bad Request with simple, bodyless GET request

**URL:** <https://community.hubspot.com/t/bad-request-with-simple-bodyless-get-request/108334>\
**Category:** APIs & Integrations\
**Tags:** workflows\
**Created:** [May 30, 2024, 7:09pm UTC](https://community.hubspot.com/t/bad-request-with-simple-bodyless-get-request/108334 "2024-05-30T19:09:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GJakobTriad](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@GJakobTriad](https://community.hubspot.com/u/GJakobTriad)\
**Post date:** [May 30, 2024, 7:09pm UTC](https://community.hubspot.com/t/bad-request-with-simple-bodyless-get-request/108334/1 "2024-05-30T19:09:55Z")

</div>

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.

```lia-code-sample
const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) => {

 // 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)

```

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.

```lia-code-sample
curl --location 'https://api.hubapi.com/crm/v4/objects/tickets/1234567890/associations/conversations?limit=1' \
--header 'Authorization: Bearer EXAMPLETOKEN'

```

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [May 31, 2024, 8:21am UTC](https://community.hubspot.com/t/bad-request-with-simple-bodyless-get-request/108334/2 "2024-05-31T08:21:53Z")

</div>

Hi @GJakobTriad

Please try with the below code

```lia-code-sample
const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) => {

 // 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)

```

“I hope this will help you out. Please mark it as **Solution Accepted and upvote** to help another Community member.  
Thanks!”

---

<div class="post-metadata">

**Author:** ![GJakobTriad](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@GJakobTriad](https://community.hubspot.com/u/GJakobTriad)\
**Post date:** [May 31, 2024, 6:32pm UTC](https://community.hubspot.com/t/bad-request-with-simple-bodyless-get-request/108334/3 "2024-05-31T18:32:05Z")

</div>

Actually the issue was that I was sending the authentication twice.

First one was implied here:

```lia-code-sample
const hubspotClient = new hubspot.Client({
 accessToken: process.env.TicketConvoControl
 });

```

So sending it as a header for **searchResults** was redundant and caused the 400 error.
