<?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: API upload a new file node.js in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/API-upload-a-new-file-node-js/m-p/835253#M66495</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/616104"&gt;@igeorge5&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason you are seeing this issue is that &lt;A href="https://developers.hubspot.com/changelog/upcoming-api-key-sunset" target="_blank" rel="noopener"&gt;API keys have been deprecated&lt;/A&gt; and are no long a valid means of authentication. As you'd correctly mentioned - private apps (or public apps using OAuth2) are the preferred approach. In order to do this with a &lt;A href="https://developers.hubspot.com/docs/api/private-apps" target="_blank" rel="noopener"&gt;private app&lt;/A&gt;, you must first create the private app and obtain an access token.&amp;nbsp; The access token is then simply included as a header in your request as opposed to a query parameter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would then need to modify your code to this:&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;request.post({
    headers: {
        'Authorization': `Bearer ${your_token}`
    },
    url: postUrl,
    formData: formData
}, function optionalCallback(err, httpResponse, body) {
    return console.log(err, httpResponse.statusCode, body);
});&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;</description>
    <pubDate>Wed, 16 Aug 2023 09:41:02 GMT</pubDate>
    <dc:creator>coldrickjack</dc:creator>
    <dc:date>2023-08-16T09:41:02Z</dc:date>
    <item>
      <title>API upload a new file node.js</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/API-upload-a-new-file-node-js/m-p/835060#M66478</link>
      <description>&lt;P&gt;Hi, I'm trying to create a API to upload a local file with node js,&amp;nbsp; I use this code from&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file" target="_blank" rel="noopener"&gt;https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var request = require('request');
var fs = require('fs');

var postUrl = 'https://api.hubapi.com/filemanager/api/v3/files/upload?hapikey=demo';

var filename = 'example_file.txt';

var fileOptions = {
    access: 'PUBLIC_INDEXABLE',
    ttl: 'P3M',
    overwrite: false,
    duplicateValidationStrategy: 'NONE',
    duplicateValidationScope: 'ENTIRE_PORTAL'
};

var formData = {
    file: fs.createReadStream(filename),
    options: JSON.stringify(fileOptions),
    folderPath: 'docs'
};

request.post({
    url: postUrl,
    formData: formData
}, function optionalCallback(err, httpResponse, body){
    return console.log(err, httpResponse.statusCode, body);
});
      &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;but I get this error&amp;nbsp;&lt;/P&gt;&lt;P&gt;null 401 {"status":"error","message":"This hapikey has been invalidated.","correlationId":"9a164839-aa7d-4a26-ab9c-f73b36cce89c","category":"EXPIRED_AUTHENTICATION","errors":[{"message":"The API key used to make this call has expired."}]}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want to acces with a&amp;nbsp;&lt;SPAN&gt;private app token but I don't how to use it. thank u.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 23:00:04 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/API-upload-a-new-file-node-js/m-p/835060#M66478</guid>
      <dc:creator>igeorge5</dc:creator>
      <dc:date>2023-08-15T23:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: API upload a new file node.js</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/API-upload-a-new-file-node-js/m-p/835253#M66495</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/616104"&gt;@igeorge5&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason you are seeing this issue is that &lt;A href="https://developers.hubspot.com/changelog/upcoming-api-key-sunset" target="_blank" rel="noopener"&gt;API keys have been deprecated&lt;/A&gt; and are no long a valid means of authentication. As you'd correctly mentioned - private apps (or public apps using OAuth2) are the preferred approach. In order to do this with a &lt;A href="https://developers.hubspot.com/docs/api/private-apps" target="_blank" rel="noopener"&gt;private app&lt;/A&gt;, you must first create the private app and obtain an access token.&amp;nbsp; The access token is then simply included as a header in your request as opposed to a query parameter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would then need to modify your code to this:&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;request.post({
    headers: {
        'Authorization': `Bearer ${your_token}`
    },
    url: postUrl,
    formData: formData
}, function optionalCallback(err, httpResponse, body) {
    return console.log(err, httpResponse.statusCode, body);
});&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;</description>
      <pubDate>Wed, 16 Aug 2023 09:41:02 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/API-upload-a-new-file-node-js/m-p/835253#M66495</guid>
      <dc:creator>coldrickjack</dc:creator>
      <dc:date>2023-08-16T09:41:02Z</dc:date>
    </item>
  </channel>
</rss>

