We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Server Discussions

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

Migrate Workflows via Admin API Powershell

igallion
7 - Meteor

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

14 REPLIES 14
JosephBih
5 - Atom

I did, and specify values for both but not even able to retrieve collections, a simple function indeed.  Does API calls require admin login or curator good enough?

 

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

 

$headers = @{
'Authorization' = 'Bearer ' + $accessToken
}
$collections = Invoke-RestMethod -Uri $baseaddress/v3/workflows -Method GET --header $headers

apathetichell
20 - Arcturus

Curator or Artisan?  documentation says Curator is good enough - but some things will require Admin... my memory is that it's better to be an admin for most of these things?

JosephBih
5 - Atom

Hi Guru, not sure where I missed out, but ran the code successfully with key/secret, no workflow uploaded.  Any idea why?

apathetichell
20 - Arcturus

No response when running $collections ?

rey01
5 - Atom

# Define API Credentials
$apiKey = "your_key"
$apiSecret = "your_secret"
$baseaddress = "https://myalteryx/webapi"

# Request Access Token
$tokenRequestBody = @{
'client_id' = $apiKey
'client_secret' = $apiSecret
'grant_type' = 'client_credentials'
}

$tokenResponse = Invoke-RestMethod -Uri "$baseaddress/oauth2/token" -Method POST -Body $tokenRequestBody -ContentType "application/x-www-form-urlencoded"

# Extract Access Token
$accessToken = $tokenResponse.access_token

# Validate Access Token
if (-not $accessToken) {
Write-Host "Failed to obtain access token" -ForegroundColor Red
exit
}

Write-Host "Access Token: $accessToken"

# Set Headers with the Access Token
$headers = @{
'Authorization' = "Bearer $accessToken"
}

# Request Collections
$collectionsUrl = "$baseaddress/v3/collections"

try {
$collections = Invoke-RestMethod -Uri $collectionsUrl -Method Get -Headers $headers
Write-Host "Collections Data:"
$collections | ConvertTo-Json -Depth 3
} catch {
Write-Host "Error retrieving collections: $_" -ForegroundColor Red
}