How To
How to upload a Python script via the POST /task/upload-script endpoint
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 here is the successful post here is the post body payload that needs to be replicated in client python code 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 from swimlane import swimlane host = 'https //swimlane host' swimlane = swimlane(host, 'user', 'password', verify ssl=false) app = swimlane apps get(name='application name') 	 resp = swimlane request( 'post', '/task/upload script', 	data=\[ 	 ("taskname", "do some cool secops py"), 	 ("scripttype", "python"), 	 ("appid", app id) 	], 	files={ 	 "file" open(r'c \swimlane\shared\do some cool secops', 'rb'), 	 "contenttype" "text/plain" 	} ) 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!