---
title: How to upload a Python script via the POST /task/upload-script endpoint
slug: user-guide-10x/how-to-upload-a-python-script-via-the-post-taskupload-script-endpoint
docTags: 
createdAt: 2025-12-15T16:14:54.142Z
---

Many of the Swimlane RESTful API endpoints require JSON payloads. However, the POST /task/upload-script endpoint requires multipart/form-data.

To learn how to interact with this endpoint, or any other, it’s best to inspect the Swimlane UI’s manner of interacting with the endpoint:

![](https://api.archbee.com/api/optimize/n8uUzk0MM4uC57-zlHNtY/I25E3DhfKKQWR7jscWj1E_image.png)

Here is the successful POST:

![](https://api.archbee.com/api/optimize/n8uUzk0MM4uC57-zlHNtY/k3iG0xdi-usUSWTkoaVTt_image.png)

Here is the POST body payload that needs to be replicated in client Python code:

![](https://api.archbee.com/api/optimize/n8uUzk0MM4uC57-zlHNtY/kaPZ-tG0vWKlnilLytOZ4_image.png)

Here is a Python 3.7 code sample, which relies on the Swimlane Driver for authentication and for ease of retrieving the pertinent application’s ID value, illustrating how to make this POST:

:::BlockQuote
from swimlane import Swimlane
host = 'https\://SWIMLANE-HOST'
swimlane = Swimlane(host, 'USER', 'PASSWORD', verify\_ssl=False)
app = swimlane.apps.get(name='APPLICATION-NAME')
&#x9;
resp = swimlane.request(
&#x20;   'post',
&#x20;   '/task/upload-script',
&#x9;data=\[
&#x9;	("taskName", "do\_some\_cool\_secops.py"),
&#x9;	("scriptType", "Python"),
&#x9;	("appId", app.id)
&#x9;],
&#x9;files=\{
&#x9;	"file": open(r'C:\Swimlane\shared\do\_some\_cool\_secops', 'rb'),
&#x9;	"contentType": "text/plain"
&#x9;}
)

print str(resp.status\_code)
print resp.text
:::


The two supported file types are .py (Python scripts) and .ps1 (Powershell scripts).

Here are some of the sources consulted in authoring the above:

- https\://swimlane-python-driver.readthedocs.io/en/stable/examples/client.html#custom-direct-requests
- https\://requests.readthedocs.io/en/master/user/quickstart/#more-complicated-post-requests
- https\://requests.readthedocs.io/en/master/user/quickstart/#post-a-multipart-encoded-file
- https\://stackoverflow\.com/questions/27553082/valueerror-data-must-not-be-a-string


Enjoy uploading scripts using Python code!
