Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Server Discussions

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

Alteryx Gallery API - Downloading Packages as a non-Admin/Curator

mcha54
8 - Asteroid

Hey All! I am working on a migration project and looking for a way as a non-Admin/Curator to mass download packages given a list of Workflow IDs. I've been looking at the /v1/ endpoints and it looks like as an Artisan I can use /v1/workflows/{appId}/package. Does anyone have an example script or workflow that uses that endpoint? I'm struggling to get the right GET request to download the .yzxps. 🤔

 

This is what chatGPT is suggesting but it returns a 401. This is what chatGPT is suggesting but it returns a 401. 

 

import requests
import os

# Define the Alteryx Server URL and workflow ID
server_url = "https://myalteryxserver.com"
# update code to feed in a list, but testing with one workflow ID for now
workflow_id = "12345"

# Specify the path to save the downloaded workflow package on the C drive
save_path = "C:/workflow.yxzp"

# Alteryx Server authorization token
auth_token = mytoken

# Construct the API endpoint URL
api_url = f"{server_url}/api/v1/workflows/{workflow_id}/package"

# Send a GET request to download the workflow package
headers = {'Accept': 'application/octet-stream',"Authorization": f"{auth_token}"}
response = requests.get(api_url, headers=headers, stream=True, verify=False)

# Check if the request was successful
if response.status_code == 200:
    # Create the directories in the save path if they don't exist
    os.makedirs(os.path.dirname(save_path), exist_ok=True)

    # Open a file in binary mode and save the downloaded package
    with open(save_path, "wb") as file:
        for chunk in response.iter_content(chunk_size=8192):
            file.write(chunk)
    print("Workflow package downloaded successfully!")
else:
    print("Failed to download the workflow package.")
2 REPLIES 2
fmvizcaino
17 - Castor
17 - Castor

Hey @mcha54 ,

 

If your server version is 21.4 or higher, I suggest using the following set of macros and building your own workflow.

https://community.alteryx.com/t5/Engine-Works/Introducing-the-Alteryx-Server-v3-API/ba-p/899228

 

I`m not experienced with python, but you are using a hard-coded token which could work if you are getting the token somewhere. Here is the endpoint for the token. https://help.alteryx.com/20223/server/server-api-configuration-and-authorization

 

Best regards,

Fernando Vizcaino

mcha54
8 - Asteroid

Thank you for the link! I did start using those Server macros, but run into the same issue. Only Admins/Curators can authenticate and use a bulk of the API calls including the one that downloads a package. Is there something that non-Admin/non-Curators can do?