<?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 Having trouble authenticating a post to upload an image to the file manager in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Having-trouble-authenticating-a-post-to-upload-an-image-to-the/m-p/972936#M73450</link>
    <description>&lt;P&gt;I have a serverless function to upload an image to the file manager, but am currently getting a 401 error (the call is not properly authenticated).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have it set up almost identically to a serverless function that pulls form submission data (which is working) and I've properly registered the secret and the function file (this is the same secret used for the form data pull, which has both forms and files scopes) so I'm not sure what I need to change about the authentication in order for HubSpot to accept it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my serverless function code for the file upload (not working, 401 error):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const axios = require('axios');

exports.main = async (context, sendResponse) =&amp;gt; {

  const config = {
    headers: {
      Authorization: `Bearer ${process.env["my_secret_key"]}`,
      'Content-Type': 'image',
    },
    body: context,
  };

  try {
    // post image to file manager
    const response = await axios.post(`https://api.hubapi.com/files/v3/files/import-from-url/async`, config);

    sendResponse({ body: { title: "Image successfully uploaded!", description: "The call to upload the image was successful.", data: response }, statusCode: 200 });
  } catch (e) {
    sendResponse({ body: { message: e.message }, statusCode: 500 });
  }
};&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;And here's my serverless function code for the form data pull (working):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const axios = require('axios');

exports.main = async (context, sendResponse) =&amp;gt; {

  const config = {
    headers: {
      Authorization: `Bearer ${process.env["my_secret_key"]}`,
      'Content-Type': 'application/json',
    },
  };

  try {
    // pull form submission data
    const response = await axios.get(`https://api.hubapi.com/form-integrations/v1/submissions/forms/{{form-id}}`, config);

    sendResponse({ body: { title: "form data successfully pulled!", description: "The call to the forms api to retrieve the submission data was successful.", data: response.data }, statusCode: 200 });
  } catch (e) {
    sendResponse({ body: { message: e.message }, statusCode: 500 });
  }
};&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;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2024 22:25:48 GMT</pubDate>
    <dc:creator>KSmithIllumine8</dc:creator>
    <dc:date>2024-05-07T22:25:48Z</dc:date>
    <item>
      <title>Having trouble authenticating a post to upload an image to the file manager</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Having-trouble-authenticating-a-post-to-upload-an-image-to-the/m-p/972936#M73450</link>
      <description>&lt;P&gt;I have a serverless function to upload an image to the file manager, but am currently getting a 401 error (the call is not properly authenticated).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have it set up almost identically to a serverless function that pulls form submission data (which is working) and I've properly registered the secret and the function file (this is the same secret used for the form data pull, which has both forms and files scopes) so I'm not sure what I need to change about the authentication in order for HubSpot to accept it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my serverless function code for the file upload (not working, 401 error):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const axios = require('axios');

exports.main = async (context, sendResponse) =&amp;gt; {

  const config = {
    headers: {
      Authorization: `Bearer ${process.env["my_secret_key"]}`,
      'Content-Type': 'image',
    },
    body: context,
  };

  try {
    // post image to file manager
    const response = await axios.post(`https://api.hubapi.com/files/v3/files/import-from-url/async`, config);

    sendResponse({ body: { title: "Image successfully uploaded!", description: "The call to upload the image was successful.", data: response }, statusCode: 200 });
  } catch (e) {
    sendResponse({ body: { message: e.message }, statusCode: 500 });
  }
};&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;And here's my serverless function code for the form data pull (working):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const axios = require('axios');

exports.main = async (context, sendResponse) =&amp;gt; {

  const config = {
    headers: {
      Authorization: `Bearer ${process.env["my_secret_key"]}`,
      'Content-Type': 'application/json',
    },
  };

  try {
    // pull form submission data
    const response = await axios.get(`https://api.hubapi.com/form-integrations/v1/submissions/forms/{{form-id}}`, config);

    sendResponse({ body: { title: "form data successfully pulled!", description: "The call to the forms api to retrieve the submission data was successful.", data: response.data }, statusCode: 200 });
  } catch (e) {
    sendResponse({ body: { message: e.message }, statusCode: 500 });
  }
};&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;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 22:25:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Having-trouble-authenticating-a-post-to-upload-an-image-to-the/m-p/972936#M73450</guid>
      <dc:creator>KSmithIllumine8</dc:creator>
      <dc:date>2024-05-07T22:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble authenticating a post to upload an image to the file manager</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Having-trouble-authenticating-a-post-to-upload-an-image-to-the/m-p/973405#M73481</link>
      <description>&lt;P&gt;Hey, &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/583645"&gt;@KSmithIllumine8&lt;/a&gt;&lt;/SPAN&gt; &lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for your question!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't have the solution, but I have two questions for you:&lt;/P&gt;
&lt;UL&gt;
 &lt;LI&gt;have you tried using "Content-Type": "image/jpeg" or "image/png"(depending on the fie type you are using) instead of just "Content-Type": "image"?&lt;/LI&gt;
 &lt;LI&gt;have you tried logging the entire error object (console.error(e)) instead of just e.message?&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Talk soon! — Jaycee&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2024 16:22:24 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Having-trouble-authenticating-a-post-to-upload-an-image-to-the/m-p/973405#M73481</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2024-05-08T16:22:24Z</dc:date>
    </item>
  </channel>
</rss>

