# Files API Overwrite not behaving

**URL:** <https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020>\
**Category:** APIs & Integrations\
**Tags:** php\
**Created:** [December 6, 2021, 2:44am UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020 "2021-12-06T02:44:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![PNie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pnie/32/44643_2.png) [@PNie](https://community.hubspot.com/u/PNie)\
**Post date:** [December 6, 2021, 2:44am UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/1 "2021-12-06T02:44:11Z")

</div>

Using  
/files/v3/files/import-from-url/async  
to pull an external file into hubspot files. This appears to work. However when the overwrite option is set to true, it doesn’t overwrite, just end up with a folder with  
test  
test-1  
test-2  
test-3  
test-4  
Then for some reason, consistently after -4 it changes to test-datetime stamp  
test-Dec-06-2021-02-39-17-81-AM  
Just running the below (where XXX = api key, file url, folderid)

```lia-code-sample
$curl = curl_init();

curl_setopt_array($curl, array(
 CURLOPT_URL => 'https://api.hubapi.com/files/v3/files/import-from-url/async?hapikey=XXX',
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_ENCODING => '',
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 0,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => 'POST',
 CURLOPT_POSTFIELDS =>'{
 "access":"PUBLIC_NOT_INDEXABLE",
 "name":"test",
 "url":"XXX",
 "duplicateValidationStrategy":"NONE",
 "duplicateValidationScope":"EXACT_FOLDER",
 "overwrite":true,
 "folderId":"XXX"
}',
 CURLOPT_HTTPHEADER => array(
 'accept: application/json',
 'content-type: application/json'
 ),
));

$response = curl_exec($curl);

curl_close($curl);

```

Just wanting it to overwrite anyone able to replicate the issue or able to point me in the right direction.

---

<div class="post-metadata">

**Author:** ![RMones](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rmones/32/82797_2.png) [@RMones](https://community.hubspot.com/u/RMones)\
**Post date:** [December 6, 2021, 3:39pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/2 "2021-12-06T15:39:23Z")

</div>

Hi @PNie ,

I can reproduce it, and have the same behaviour.

It looks that the parameter overwrite is not accepted or ignored by the async API.

I found the following information

```lia-code-sample
Overwrite:
If true this file with replace any existing files with the name name, folder, and type.

Note: If this is set to false, and the uploaded file matches the filename of an existing file in the same folder, the file will be uploaded with a number incremented filename (e.g. example_file.txt will become example_file-1.txt)

```

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

I tried is also with the synchronious endpoint, and that one is accepting the overwrite parameter and is updating the file with overwrite. ([https://api.hubapi.com/filemanager/api/v3/files/upload?hapikey=xxx](https://api.hubapi.com/filemanager/api/v3/files/upload?hapikey=xxx))

Maybe @dennisedson can tell us if this function isn’t implemented in the async API?

Regards Ronald

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [December 8, 2021, 4:48pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/3 "2021-12-08T16:48:20Z")

</div>

Will look into this 🤔

---

<div class="post-metadata">

**Author:** ![mike-thomas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mike-thomas/32/30838_2.png) [@mike-thomas](https://community.hubspot.com/u/mike-thomas)\
**Post date:** [December 13, 2021, 6:45pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/4 "2021-12-13T18:45:58Z")

</div>

This issue is blocking me too 😞

---

<div class="post-metadata">

**Author:** ![LCantos](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@LCantos](https://community.hubspot.com/u/LCantos)\
**Post date:** [February 7, 2022, 2:01pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/5 "2022-02-07T14:01:58Z")

</div>

Any news on this issue? I’m still having issues with the overwrite option.  
Thank you,

---

<div class="post-metadata">

**Author:** ![MDeladi](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@MDeladi](https://community.hubspot.com/u/MDeladi)\
**Post date:** [February 12, 2022, 3:24pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/6 "2022-02-12T15:24:05Z")

</div>

Hello!

Just checking to see if anyone found a resolution to this. I am running into the same issue.

Thanks!

---

<div class="post-metadata">

**Author:** ![mike-thomas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mike-thomas/32/30838_2.png) [@mike-thomas](https://community.hubspot.com/u/mike-thomas)\
**Post date:** [March 14, 2022, 2:39pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/7 "2022-03-14T14:39:15Z")

</div>

Any update on this one please @dennisedson ?

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [March 14, 2022, 2:45pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/8 "2022-03-14T14:45:36Z")

</div>

@mike-thomas ,

Believe it or not, I received a message on Friday that this was resolved! feel free to yell at me if it is still not working.

---

<div class="post-metadata">

**Author:** ![mike-thomas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mike-thomas/32/30838_2.png) [@mike-thomas](https://community.hubspot.com/u/mike-thomas)\
**Post date:** [March 14, 2022, 3:01pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/9 "2022-03-14T15:01:14Z")

</div>

Oh yes… Seems to working! Fantastic! 👍

---

<div class="post-metadata">

**Author:** ![ghostcat](https://avatars.discourse-cdn.com/v4/letter/g/e9bcb4/32.png) [@ghostcat](https://community.hubspot.com/u/ghostcat)\
**Post date:** [February 10, 2023, 9:48pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/10 "2023-02-10T21:48:41Z")

</div>

Hi, i’m having a similar issue. I’m using

`/files/v3/files/import-from-url/async`

in a serverless function to write a json file to a folder. Here’s my code:

```lia-code-sample
const axios = require('axios');
exports.main = async (context, sendResponse) => {
 const response = await axios.post(
 'https://api.hubapi.com/files/v3/files/import-from-url/async',
 {
 'access': 'PUBLIC_INDEXABLE',
 'name': 'MY_FILENAME.json',
 'url': 'MY_JSON_URL_TO_IMPORT',
 'folderPath': 'MY_FOLDER',
 'duplicateValidationStrategy': 'NONE',
 'duplicateValidationScope': 'ENTIRE_PORTAL',
 'overwrite': true
 },
 {
 headers: {
 'authorization': 'Bearer MY_TOKEN',
 'content-type': 'application/json'
 }
 }
 );
 sendResponse({body: JSON.stringify(response.data), statusCode: 200});
};

```

The first time, it works fine. MY\_FILENAME.json file is put in the folder, no problem. The second time I run it, Instead of overwriting the file, a new file is added to the folder with an extra .json extension added (e.g.MY\_FILENAME.json.json). Any subsequent API calls will overwrite the MY\_FILENAME.json.json file, but leaves the original MY\_FILENAME.json file unchanged. Any help?

---

<div class="post-metadata">

**Author:** ![lstepany](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lstepany/32/54675_2.png) [@lstepany](https://community.hubspot.com/u/lstepany)\
**Post date:** [April 5, 2023, 8:22pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/11 "2023-04-05T20:22:17Z")

</div>

I have the same issue. Both API endpoints for overwritting and replacing the file just don’t work ((

---

<div class="post-metadata">

**Author:** ![lstepany](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lstepany/32/54675_2.png) [@lstepany](https://community.hubspot.com/u/lstepany)\
**Post date:** [April 5, 2023, 8:23pm UTC](https://community.hubspot.com/t/files-api-overwrite-not-behaving/48020/12 "2023-04-05T20:23:18Z")

</div>

There are 2 API endpoint and the one that I use is defenitly not working ((

[https://api.hubapi.com/filemanager/api/v3/files/upload](https://api.hubapi.com/filemanager/api/v3/files/upload)
