# Automate post api by uploading (xlsx or csv or xml file) via robotFramework

**URL:** <https://forum.robotframework.org/t/automate-post-api-by-uploading-xlsx-or-csv-or-xml-file-via-robotframework/5704>\
**Category:** RequestsLibrary\
**Created:** [13 May 2023 14:50 UTC](https://forum.robotframework.org/t/automate-post-api-by-uploading-xlsx-or-csv-or-xml-file-via-robotframework/5704 "2023-05-13T14:50:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgrissa94](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/mgrissa94/32/2635_2.png) [@mgrissa94](https://forum.robotframework.org/u/mgrissa94)\
**Post date:** [13 May 2023 14:50 UTC](https://forum.robotframework.org/t/automate-post-api-by-uploading-xlsx-or-csv-or-xml-file-via-robotframework/5704/1 "2023-05-13T14:50:25Z")

</div>

I am getting a HTTPError: 400 Client Error: Bad Request for url ; when I run the following robot test case which aims to automate POST api. I have no issue when I run the api via postman by uploading an xlsx file in the body then running the api

```python
***Settings***
Library RequestsLibrary
Library OperatingSystem
Library Collections

***Variables***
${API_URL} https://xxxxxxxxxxxxxxxxxxxxx.net
${FILE_PATH} path-to-my-file/products.xlsx

***Test Cases***
Upload XLSX File Test
    [Documentation] Upload XLSX file with parameters and verify 201 response
    ${file}= Get File For Streaming Upload ${FILE_PATH}
    ${files}= Create Dictionary file=${file} operator_format=false Content-Type=multipart/form-data
    ${headers}= Create Dictionary Authorization=xxxxxxxxxxxxxxxxxxxxxxxxxxx Accept=application/json Content-Type=multipart/form-data    
    Create Session mySession ${API_URL} verify=false
    ${response}= POST On Session mySession /api/products/imports headers=${headers} data=${files}
    Should Be Equal As Strings ${response.status_code} 201

```

---

<div class="post-metadata">

**Author:** ![automat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/automat/32/2973_2.png) [@automat](https://forum.robotframework.org/u/automat)\
**Post date:** [6 September 2023 21:26 UTC](https://forum.robotframework.org/t/automate-post-api-by-uploading-xlsx-or-csv-or-xml-file-via-robotframework/5704/2 "2023-09-06T21:26:06Z")

</div>

I have similar issue. Did you figure out what was the issue? Thanks

---

<div class="post-metadata">

**Author:** ![UITester](https://avatars.discourse-cdn.com/v4/letter/u/6a8cbe/32.png) [@UITester](https://forum.robotframework.org/u/UITester)\
**Post date:** [7 September 2023 06:14 UTC](https://forum.robotframework.org/t/automate-post-api-by-uploading-xlsx-or-csv-or-xml-file-via-robotframework/5704/3 "2023-09-07T06:14:16Z")

</div>

I am also facing similar issue. Can any one help out please?

---

<div class="post-metadata">

**Author:** ![xdenis1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/xdenis1/32/4592_2.png) [@xdenis1](https://forum.robotframework.org/u/xdenis1)\
**Post date:** [25 February 2025 15:26 UTC](https://forum.robotframework.org/t/automate-post-api-by-uploading-xlsx-or-csv-or-xml-file-via-robotframework/5704/4 "2025-02-25T15:26:19Z")

</div>

Have you already resolved your issue?  
Did you try using `Get Binary File` (OperatingSystem library) instead of `Get File For Streaming Upload` ?

---

<div class="post-metadata">

**Author:** ![silvestersymon](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@silvestersymon](https://forum.robotframework.org/u/silvestersymon)\
**Post date:** [15 May 2025 14:37 UTC](https://forum.robotframework.org/t/automate-post-api-by-uploading-xlsx-or-csv-or-xml-file-via-robotframework/5704/5 "2025-05-15T14:37:09Z")

</div>

Hello Friends,  
Did someone resolved this issue, By some how.  
I am facing similler issue.
