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!
Our main navigation will be under construction for the next hour. "Launch Pad" will be moving to "Learn", and the "Introduce Yourself" forum will be moving to a thread in the "General" discussion.

Alteryx Server Discussions

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

Migrate Workflows via Admin API Powershell

6 - Meteoroid

Does anyone have an example of migrating workflows between Alteryx servers with Powershell 5.1? Specifically, I'm looking for an example of how to format the Multipart/Form-Data request to upload a workflow to the destination server (the Post /admin/v1/workflows/ endpoint).

11 - Bolide


I've done this in Python in Alteryx release 2021.3.  I used Python code found here:




If you can translate to Powershell...


I added this to the above code to get the WF package


def getAppAdmin(self, appId):
method = 'GET'
url = self.api_location + '/' + 'admin/v1/' + appId + '/package/'
params = self.build_oauth_params()
signature = self.generate_signature(method, url, params)
params.update({'oauth_signature': signature})
local_filename = 'D:\\Jupyter\\AlteryxAPI\\' + appId + '.yxzp'
# NOTE the stream=True parameter below
with requests.get(url, stream=True, params=params) as yxzp:
with open(local_filename, 'wb') as f:
for chunk in yxzp.iter_content(chunk_size=8192):
if chunk: # filter out keep-alive new chunks
# f.flush()


Hope that helps.

6 - Meteoroid

Thanks for the reply! I'm actually looking for advice on using the /admin/v1/workflows Post endpoint to upload a workflow to one Alteryx server from another. In my script I've successfully been able to check for migratable workflows, download the workflows and reset the migrate flag. What I'm having trouble with is formatting the request to upload the workflows to the new environment after they've been downloaded as a .yxzp file.

11 - Bolide


I'm pretty much at the same point as you.  I've gotten all endpoints to work in a Python script except this one.  My company is exploring automating implementation but we're just starting.  I did find this just now and it may help.










6 - Meteoroid
Here is what I have so far for reference. When running this I get unauthorized and internal server errors:    
#Upload workflows to Prod environment
    $packages = Get-ChildItem $AlteryxMigrateFolder -Recurse -Include *.yxzp
    foreach ($package in $packages){
        $boundary = [System.Guid]::NewGuid().ToString()
        $fileBytes = [System.IO.File]::ReadAllBytes($package.FullName);
        $fileEnc = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytes);
        $workflowName = $package.Name.Split(".")[0]
        $fileName = $package.Name
        $LF = "`r`n"
        $body = (
            "Content-Disposition: form-data; name=`"file`"; filename=`"$fileName`"",
            "Content-Type: application/json$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",
        ) -join $LF
Invoke-RestMethod -Uri $finalUri -Method Post -ContentType "application/json; boundary=`"$boundary`"" -Body $body -Verbose
11 - Bolide

We got it working in Postman.  We're Server 2021.3, I used Server Admin Key and Secret.  We Set SSL Certification to Off.  




6 - Meteoroid

I have solved this and in short - upgrade to version 2021.3+ and use the oauth 2.0 endpoints.


Authenticating using oauth 2.0 is infinitely simpler than oauth 1.0 and the v3 API endpoints add some great new features. Here's a simple example of using the v3 API to get a list of gallery collections:


$baseaddress = "https://YourServerName/webapi"

$tokenRequestBody = @{

        'client_id' = $apiKey
        'client_secret' = $apiSecret
        'grant_type' = 'client_credentials'

$accessToken = invoke-restmethod -uri $baseaddress/oauth2/token -method POST -body $tokenRequestBody


 $headers = @{
     'Authorization' = 'Bearer ' + $accessToken
$collections = Invoke-RestMethod -Uri $baseaddress/v3/collections? -Method Get  -Headers $headers
Here is an example of how to upload a workflow using the v3/workflows POST endpoint. I used cURL instead of invoke-restmethod since powershell 5.0 does not natively support multipart/form-data. Using cURL is much easier than manually formatting for invoke-restmethod:
$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)