# Help needed uploading Data to Hugging Face Dataset via Apps Script

**URL:** <https://discuss.huggingface.co/t/help-needed-uploading-data-to-hugging-face-dataset-via-apps-script/137986>\
**Category:** Beginners\
**Created:** [January 29, 2025, 10:24pm UTC](https://discuss.huggingface.co/t/help-needed-uploading-data-to-hugging-face-dataset-via-apps-script/137986 "2025-01-29T22:24:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jago2025](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jago2025/32/40058_2.png) [@jago2025](https://discuss.huggingface.co/u/jago2025)\
**Post date:** [January 29, 2025, 10:24pm UTC](https://discuss.huggingface.co/t/help-needed-uploading-data-to-hugging-face-dataset-via-apps-script/137986/1 "2025-01-29T22:24:03Z")

</div>

Hi everyone,

I’m trying to upload data to my Hugging Face dataset using the following Apps Script, but it seems to be giving me an error. Can anyone confirm if the API URL I’m using is correct? Or is there another API endpoint I should use to upload a small file to my dataset?

Any feedback on what I’m doing wrong or how to correctly use the API to upload a file to my Hugging Face dataset would be much appreciated!

Thank you in advance!

Here’s the Apps Script I am using:

function pushDataToHuggingFace() {  
const token = ‘[my Token]’;  
const datasetRepo = ‘[user]/[my dataset name]’;

// 1. Get data from Google Sheets  
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(‘Keywords’);  
const data = sheet.getRange(‘A2:B11’).getValues();

// 2. Convert data to valid JSONL format  
const jsonlContent = data.map(row =\>  
JSON.stringify({ include: row[0], exclude: row[1] })  
).join(‘\n’);

// 3. Set up request with the updated API URL  
const url = `https://huggingface.co/api/datasets/${datasetRepo}/commit/main`;  
const options = {  
method: ‘PUT’,  
headers: {  
‘Authorization’: `Bearer ${token}`,  
‘Content-Type’: ‘application/json’  
},  
payload: JSON.stringify({  
files: [{  
path: ‘data/datos.jsonl’,  
content: Utilities.base64Encode(jsonlContent),  
encoding: ‘base64’  
}],  
commit\_message: ‘Update from Google Sheets’,  
repo\_type: ‘dataset’  
}),  
muteHttpExceptions: true  
};

// 4. Execute and handle response  
try {  
const response = UrlFetchApp.fetch(url, options);  
const code = response.getResponseCode();

```
if (code === 200 || code === 201) {
  Logger.log(`✅ Success! Verify here: https://huggingface.co/datasets/${datasetRepo}/tree/main/data`);
} else {
  Logger.log(`❌ Error ${code}: ${response.getContentText()}`);
}

```

} catch (error) {  
Logger.log(`🔥 Error: ${error.message}`);  
}  
}

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [January 30, 2025, 6:28am UTC](https://discuss.huggingface.co/t/help-needed-uploading-data-to-hugging-face-dataset-via-apps-script/137986/2 "2025-01-30T06:28:40Z")

</div>

Since errors are likely to occur with normal web requests, it is easier to use libraries.

> **[Hugging Face JS libraries](https://huggingface.co/docs/huggingface.js/index)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.
