The Alteryx Server API service enables quite interesting features from a technical perspective. (e.g. to get users, subscription, workflows, starts jobs, ...)
With the new release of the newest Alteryx Server 2022.1, many improvements and change were introduced, and this time, also the authentication method changed quite significantly as the API changed from oauth1 to oauth2 and the legacy oauth1 were removed. (https://help.alteryx.com/release-notes/server/server-20221-release-notes)
In the past, we were utilizing the Alteryx API package from github (https://github.com/Theamazingdp/AlteryxGalleryAPI) which included the authentication method, signing method to directly connect to the API and also simply allowed us to connect to the Alteryx Server and trigger first API calls.
(especially interesting for us was the starting point with the Gallery class: https://github.com/Theamazingdp/AlteryxGalleryAPI/blob/master/AlteryxGalleryAPI.py)
The new method is not covered yet in this package. (hopefully, it does soon) And I didn’t find a solution online & also had my struggles with the Alteryx support on this one.
Getting from oauth1 to oauth2 for the Alteryx Gallery
So, let’s summarize the steps to get from the existing solution to the adjusted one.
The oauth2 method is now build in two steps: First get an access token (time constraint) and secondly use the access token to use the API.
Using python, firstly define a function to get the access token
def get_access_token():
json.loads(requests.post(self.gallery_url+'/webapi/oauth2/token',data={'client_id':self.api_key, 'client_secret':self.api_secret, 'grant_type':'client_credentials'}).text)['access_token']Utilizing the gallery Url (e.g. https://www.mygallery.com), API key, API secret key from the Alteryx Gallery.
With this token, instead of using the signing method, the API call requires "only" the access token:
def get_subscriptions():
method = 'GET'
url = self.api_location + '/webapi/admin/v1/subscriptions/'
headers = {'Authorization':'Bearer ' + self._access_token}
output = requests.get(url, headers=headers)
output, output_content = output, json.loads(output.content.decode("utf8"))
Looking back, the generation of access token was indeed the trickiest part of the change.