Happy 8th birthday to the Maveryx Community! Take a walk down memory lane in our birthday blog, and don't miss out on the awesome birthday present that all Maveryx Community members get to take advantage of!

Alteryx Server Discussions

Find answers, ask questions, and share expertise about Alteryx Server.

POST Alteryx Workflow to the Server using API

7 - Meteor

Hi Wonderful Team,


We are trying to build an automated workflow promotion process to Alteryx Server using Powershell.


We referred to the below posts:




and various other places to build our solution(in PowerShell). Currently we were able to authenticate, get migratable objects from one server, download the workflow as .yxzp package. However when we tried to POST the package to production we were facing troubles.


API Body Code attached below:


$boundary = [System.Guid]::NewGuid().ToString()
$file = "<file full path>\file.yxzp" #change it
$name = "Success_File"
$owner = "<valid mail id>" #change it
$validate = "True"
$isPublic = "True"
$sourceId = "<Source ID of the workflow>" #change it
$workerTag = ""
$canDownload = "True"
$comments = ""

$LF = "`r`n"
$bodyLines = (
"Content-Disposition: form-data; name=`"file`"; filename=`"file.yxzp`"Content-Type: {contentType}$LF",
"Content-Disposition: form-data; name=`"name`"$LF",
"Content-Disposition: form-data; name=`"owner`"$LF",
"Content-Disposition: form-data; name=`"validate`"$LF",
"Content-Disposition: form-data; name=`"isPublic`"$LF",
"Content-Disposition: form-data; name=`"sourceId`"$LF",
"Content-Disposition: form-data; name=`"workerTag`"$LF",
"Content-Disposition: form-data; name=`"canDownload`"$LF",
"Content-Disposition: form-data; name=`"comments`"$LF",
) -join $LF


We are calling the API using :


Invoke-RestMethod $finalUri -Method POST -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines



When we run this we are getting the following error:

HTTP Error 404. The requested resource is not found.


Please guide us through this problem.





14 - Magnetar

I cannot read PowerShell, but what is the endpoint you are trying to reach? Based on the error (404) it seems that the endpoint does not exist. I also encourage you to test the API in swagger. 



7 - Meteor

Thanks gabriel for your time and effort.


I have planning to use the same Auth mechanism as shown in the "Legacy OAuth 1 API documentation".


I reckon in this case I have to pass the parameters as forms data.





I had created the form in the same way as shown in the example. (written in previous post).


May I know what information should go in high lighted text? 

Content-Disposition: form-data; name="file"; filename="{fileName}"Content-Type: {contentType}

Is it: filename = name of the file/name with complete path.

contextType = multipart/form-data?

fileContents = get-content from the file?


Sorry for being naive. I am new to the world of APIs. 

6 - Meteoroid



Please see the topic I opened here (one of the topics you linked above): https://community.alteryx.com/t5/Alteryx-Server-Discussions/Migrate-Workflows-via-Admin-API-Powershe...


While I upgraded my server version to a version that uses the oauth 2.0 endpoints, you should be able to successfully create the post request using cURL. Note that my example uses oauth 2.0 authentication and not 1.0, so you will have to make changes around that, but the body should get you on the right path. I believe this is now installed with Windows by default, but I'd highly recommend using cURL over invoke-restmethod in this case. I was never able to correctly format the request using invoke-restmethod. Here's the snippet from the article linked above:


$uploadReq = .\curl.exe -s -k -X POST --header 'Content-Type: multipart/form-data' "https://YourServer/webapi/v3/workflows" --header 'Accept: application/json' --header "Authorization: Bearer $accessToken" `
--form "file=@$workflowFilePath" `
--form "name=$workflowName" `
--form "ownerId=$ownerID" `
--form 'isPublic="false"' `
--form 'isReadyForMigration="false"' `
--form 'othersMayDownload="true"' `
--form 'othersCanExecute="true"' `
--form "comments=$workflowComments" `
--form 'executionMode="Standard"'
#Print results (new workflow ID is returned if successful)
7 - Meteor

Thanks @igallion . Both Invoke-restmethod and invoke-webrequest are so painful to format when it comes to "formData"


For anyone who is working on powershell API calls to Alteryx Server - the above code works and the cleanest way to call! just replace .\curl.exe to path where curl is installed ( C:\Windows\System32\curl.exe) in my case. 


Heard that post powershell 6, curl is not shipped with windows. But I would say it is worth to install it :-)