Note: Alteryx Server received a number of enhancements with the 2021.4 release. For the 2021.4 release and beyond, please refer to this updated article on server runner macros.
Workflow orchestration is a topic that inevitably arises among seasoned Alteryx users. There are 3 scenarios we hear about most frequently.
Batch macros are well suited for orchestrating workflows, but some use cases may be especially unique. If you’ve exhausted your options with batch macros, you may have turned to the Runner Tool or the CReW macros. While useful in Alteryx Designer, these tools are not supported on Alteryx Server. Fortunately, there is another option. This article will help you get started building your own “runner” macro – with supported tools – and in the process demystify the Alteryx Server API.
In a coming release, to streamline your asset management, subscriptions (studios) are going away. Accordingly, Server will also see changes to the API, including an Oauth2.0 framework. The steps below should only be referenced for versions 2021.3 and earlier. You should plan to document workflows interacting with a current version of the API as they will need to be updated as part of a Server upgrade.
This article is long and yet there is more that could be said on these subjects. With that in mind, this content is intended for users with a working understanding of RESTful APIs, JSON, building Alteryx macros, and the Alteryx Developer tools. It will not cover the basics. If you are new to these concepts, you can get started with the links under Additional Resources.
Most of what follows is a guide for constructing, authenticating, and submitting requests to the Alteryx Server API, rather than a step-by-step workflow tutorial. As a supplement, there are two working macro examples attached:
Feel welcome to reference these macros or modify them to suit your needs. Examples of how these macros can be used within a workflow are shown at the end of the article. You should thoroughly test these macros before using them in your production environment.
The Alteryx Server API supports both user and administrative interactions with the Server. This article only focuses on user (subscription) endpoints, but the steps outlined are useful for either. Full documentation on the API is available at http(s)://your.companies.server/gallery/api-docs/.
Server administrators must enable API access in the Server UI. From the Admin portal, navigate to the subscription that should be granted access, toggle API Enabled to “Yes”, then save the changes.
Once API access is enabled on the subscription, users within that subscription can obtain the Key and Secret. Log into the Server UI and choose My Profile while hovering over your name in the top right corner, the Key and Secret will be located on the Keys tab. The Key and Secret values used in the subsequent examples are not real. Never share your API credentials!
With your Key and Secret in hand, you can now begin building out a request to the Server API. The following example will focus on running a workflow on the Server (creating a job), but the steps could be modified to interact with other API endpoints. In the macro examples, a Formula tool is used to create all parts of the request strings.
The components of the URL string are show in the diagram below. The base URL to your company’s Alteryx Server should be https. Documentation on all API endpoints is available at http(s)://your.companies.server/gallery/api-docs/.
This endpoint requires that you include the ID of the app that you want to execute. To obtain the app ID, navigate to the app in the Server UI and click into it. Copy the string following the final forward slash “/” in the URL, this is the app ID. App IDs may also be retrieved programmatically by submitting a GET request to the subscription endpoint.
The following parameters must be included in each request.
PARAMETER |
VALUE |
oauth_consumer_key |
The Key obtained from your Server profile |
oauth_nonce |
A unique random string |
oauth_signature_method |
HMAC-SHA1 |
oauth_timestamp |
Calculated as seconds since midnight on January 1, 1970 |
oauth_version |
The only optional parameter, but if included must be 1.0 |
In the example macros, the following expressions were used to generate the parameter values below. The oauth_nonce parameter could be generated many ways; this is just one way.
The parameter string is constructed by appending the parameter name with its value, separated by “=”. Combine all name value pairs separating each with “&”. Your parameter string will look like the diagram below.
The signature base string is one of the inputs used to generate the authentication signature. There are 3 components to the signature:
Below is an example of what the signature base string will look like.
Append a single “&” to the end of the Secret obtained for your profile. This is the second input required for generating the authentication signature.
Alteryx does not have a built-in function for HMAC-SHA1 encryption. For this step, you will need to leverage a script to generate the signature. The attached Create Oauth Signature macro will execute this step for you using Python. Or you could write your own! If you are using the attached macro to generate the signature, map the following fields:
The macro will output a new field containing the signature. This is the final parameter needed to authenticate your request.
You now have all the pieces needed to create the final request string.
If the app you are executing accepts inputs with Interface tools, you can pass these inputs in the body of the request. To do so, each input value must be associated with the Interface tool’s name. The name is defined in Alteryx Designer in the Configuration window, on the Annotation tab. In the example below, the Text Box displays “Enter your text”, but the tool’s name is “text_box_1”.
The JSON body below would pass a value of “This is my input!” to text_box_1 when the workflow is executed.
The example runner macro accepts question inputs using a List Box tool. The user can select fields to include, and they will be formatted and submitted in the request body. The field name must match the Interface tool’s name to execute correctly.
Use a Download tool to submit the request. On the Basic tab select the request field created in Step 6.
On the Headers tab, specify the Content-Type as application/json.
On the Payload tab, choose the correct HTTP action.
Finally, if you are submitting question inputs in the body, select this option on the Payload tab and map the body field.
Congratulations! You’ve submitted your first request to the Alteryx Server API. The Download tool outputs 2 fields:
Once you have your macros functional, you can use them in workflows to interact with other apps on the Server. Using the example macros, the three scenarios outlined at the beginning of the article are shown below.
In the example below, the runner macro is the final tool in the workflow. The Block Until Done tool is used to ensure all records are written to the database before the request to the Server API is made. The example runner macro will execute 1 API request per row of incoming data. A Sample tool is used prior to the runner macro to ensure that only 1 request is made. The runner macro creates a job on the Server for the next app in the sequence.
As mentioned, the example runner macro will submit 1 request to the Server API for each row of incoming data. The goal of simultaneous execution is to run the same workflow with different inputs. Running them simultaneously reduces the overall processing time. In the example below, the column text_box_1 contains 3 rows of data, or the three inputs we want to run through the app. The runner will create a new job on the Server for each input.
When a job is created through the Server API, it does not wait until that job has completed before returning a response. It simply creates the job on the Server, then returns a response indicating if the job was successfully created. Using the example macros in tandem enables nested execution. In the example below, the runner creates a new job on the Server. The newly created job id is passed to the job status macro which checks the status each minute until the job is complete. Read the considerations before proceeding with a nested execution.
As you can see, the Server API unlocks many powerful capabilities with the Alteryx platform. Third party applications can also interact with the API to execute Alteryx apps. That said, it is important to be mindful of your Server’s configuration so that you do not inadvertently cause issues. Partner with your server administrator and your IT team to determine who should have API access and in which contexts. Below are a few critical items to consider when using the Server API.
Matt Orr has been in the data and analytics field for over a decade holding roles in Business Intelligence, Data Science, and Data Strategy. As a Solution Engineer, he enjoys supporting customers achieve analytics transformation with the Alteryx platform.
Matt Orr has been in the data and analytics field for over a decade holding roles in Business Intelligence, Data Science, and Data Strategy. As a Solution Engineer, he enjoys supporting customers achieve analytics transformation with the Alteryx platform.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.