Not able to pass Auth headers while sending POST request in crm cards(React)

Hi , i had posted a question previously on how to connect my rest api to a frontend ,i got a response of using ui extensions and CRM cards.
However i found out that only GET requests work in the React library , im trying to send Auth bearer token to my backend via the auth headers in Hubspot.fetch() using POST request in order authorize the user.
However im not able to send post requests and i get invalid url error.
Any solutions?
Thank you!

Hi @DigvijayNarayan, I hope that you are well!
Thank you for asking the HubSpot Community!
I believe you are referring to this previous post “need to connect my Hubspot Rest api”.
I have checked for you and I can see on this documentation “Fetching data for public apps (BETA)” the specific note saying that while you can use hubspot.fetch() to pass an Authorization request header, hubspot.fetch() does not pass other client-supplied request headers or return response headers set by your back-end server.
Is it the documentation/function that you are using?
I’d love to put you in touch with our Top Experts: Hi @kosalaindrasiri, @SteveHTM and @evaldas do you have any insights to share with @DigvijayNarayan, please?
Have a lovely day and thanks so much in advance for your valuable contributions! :heart:
Bérangère

Yes that is the documentation im referring, i want to send a POST request.
this is the sort of code snippet/template
```

const response = await hubspot.fetch(“my-api-endpoint”, {

method: “POST”,

headers: {

“Content-Type”: “application/json”,

“Authorization”: `Bearer ${myToken}`

},

body: JSON.stringify(requestBody)

});
```
while checking the network tab i can see that the proxy server has something to do with the headers.

DigvijayNarayan_1-1746176795368.png

Thanks for the mention @BérangèreL,

Hey @DigvijayNarayan, ​

When working with HubSpot CRM cards and attempting to send POST requests with custom headers (such as an Authorization bearer token) using hubspot.fetch() in a React-based UI extension, you might encounter limitations due to HubSpot’s security policies and the design of its fetch proxy.

The hubspot.fetch() method is primarily designed for GET requests and may not support custom headers or POST requests as expected. This is because HubSpot’s fetch proxy can restrict certain HTTP methods and headers to maintain security and integrity within the CRM environment.

To overcome these limitations, consider the following approaches:

  1. HubSpot Serverless Functions
    HubSpot provides serverless functions that allow you to execute backend code within the HubSpot environment. You can create a serverless function to handle the POST request to your external API, including setting custom headers like the Authorization token. ( Refer: Hello World: Creating Your First React + GraphQL Custom Card for HubSpot’s CRM ),
  2. External Middleware or Proxy Server
    If serverless functions are not suitable, you can set up an external middleware or proxy server that your CRM card communicates with. This server would handle the POST requests and include the necessary headers before forwarding the request to your external API.

Additional Resource: https://community.hubspot.com/t5/APIs-Integrations/Custom-Headers-in-CRM-Cards/m-p/1002220/highlight/true#M74817

Regards,

Kosala

I am using a public app , so i cant continue with serverless functions.
I think i can do the 2nd approach where i can send a get request in a proxy server and that in turn sends a post request to my rest api.
Thanks @kosalaindrasiri @BérangèreL