Free Trial

Alteryx Server Discussions

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

POST Alteryx Workflow to the Server using API

arunkumark_21
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:

https://community.alteryx.com/t5/Alteryx-Server-Knowledge-Base/Migrating-Workflows/ta-p/335774

https://community.alteryx.com/t5/Alteryx-Server-Discussions/Migrate-Workflows-via-Admin-API-Powershe...

 

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 = (
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"file.yxzp`"Content-Type: {contentType}$LF",
"$file",
"--$boundary",
"Content-Disposition: form-data; name=`"name`"$LF",
"$name",
"--$boundary",
"Content-Disposition: form-data; name=`"owner`"$LF",
"$owner",
"--$boundary",
"Content-Disposition: form-data; name=`"validate`"$LF",
"$validate",
"--$boundary",
"Content-Disposition: form-data; name=`"isPublic`"$LF",
"$isPublic",
"--$boundary",
"Content-Disposition: form-data; name=`"sourceId`"$LF",
"$sourceId",
"--$boundary",
"Content-Disposition: form-data; name=`"workerTag`"$LF",
"$workerTag",
"--$boundary",
"Content-Disposition: form-data; name=`"canDownload`"$LF",
"$canDownload",
"--$boundary",
"Content-Disposition: form-data; name=`"comments`"$LF",
"$comments",
"--$boundary--$LF"
) -join $LF
$bodyLines

 

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.

 

Thanks,

Arun

 

4 REPLIES 4
gabrielvilella
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. 

gabrielvilella_0-1675184934777.png

 

arunkumark_21
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.

 

 

 

arunkumark_21_0-1675415659731.png

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}
{fileContents}

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. 

igallion
7 - Meteor

Arun,

 

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)
$uploadReq
arunkumark_21
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 :-)

 

Thanks

Arun