# API upload a new file node.js

**URL:** <https://community.hubspot.com/t/api-upload-a-new-file-node-js/87572>\
**Category:** APIs & Integrations\
**Tags:** free\
**Created:** [August 15, 2023, 11:00pm UTC](https://community.hubspot.com/t/api-upload-a-new-file-node-js/87572 "2023-08-15T23:00:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![igeorge5](https://avatars.discourse-cdn.com/v4/letter/i/45deac/32.png) [@igeorge5](https://community.hubspot.com/u/igeorge5)\
**Post date:** [August 15, 2023, 11:00pm UTC](https://community.hubspot.com/t/api-upload-a-new-file-node-js/87572/1 "2023-08-15T23:00:04Z")

</div>

Hi, I’m trying to create a API to upload a local file with node js, I use this code from

[https://legacydocs.hubspot.com/docs/methods/files/v3/upload\_new\_file](https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file)

```lia-code-sample
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);
});

```

but I get this error

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.”}]}

Now I want to acces with a private app token but I don’t how to use it. thank u.

---

<div class="post-metadata">

**Author:** ![coldrickjack](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/coldrickjack/32/6684_2.png) [@coldrickjack](https://community.hubspot.com/u/coldrickjack)\
**Post date:** [August 16, 2023, 9:39am UTC](https://community.hubspot.com/t/api-upload-a-new-file-node-js/87572/2 "2023-08-16T09:39:46Z")

</div>

Hi @igeorge5,

The reason you are seeing this issue is that [API keys have been deprecated](https://developers.hubspot.com/changelog/upcoming-api-key-sunset) 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 [private app](https://developers.hubspot.com/docs/api/private-apps), you must first create the private app and obtain an access token. The access token is then simply included as a header in your request as opposed to a query parameter.

You would then need to modify your code to this:

```lia-code-sample
request.post({
 headers: {
 'Authorization': `Bearer ${your_token}`
 },
 url: postUrl,
 formData: formData
}, function optionalCallback(err, httpResponse, body) {
 return console.log(err, httpResponse.statusCode, body);
});

```
