Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ This is one of

Make sure to save the file.

### `api_project_id.txt`

In the downloaded `cloud-api-example-code` folder, open `api_project_id.txt`.

Populate this file with your application ID from Alteryx Analytics Cloud.

1. Visit <https://us1.alteryxcloud.com/cloud-portal/library/alteryx-io> (or <https://eu1.alteryxcloud.com/cloud-portal/library/alteryx-io> or <https://au1.alteryxcloud.com/cloud-portal/library/alteryx-io> for other regions). Ensure that you're logged in to the workspace in which you wish to use APIs. ![The developer console page](images/devConsole.png)

1. Click the "+ New" button to create a new API Project. Enter a name for your new project, then click "Save". ![Naming the API project](images/newProject.png)

1. You should see your new project in the list of projects. ![Project listing](images/listOfProjects.png)

1. Click on the project and copy the API Project ID to your clipboard. ![Copying API Project ID](images/copyingApiProjectId.png)

1. Open the `api_project_id.txt` file in this repository, and paste in the copied API Project ID. Be sure to save the file. ![API Project ID file](images/apiProjectIdFile.png)

### `creds.json`

In the downloaded `cloud-api-example-code` folder, open `creds.json`.
Expand Down Expand Up @@ -150,19 +134,6 @@ The expected output looks like:

## Troubleshooting

### `Invalid ApiKey`

```json
{
fault: {
faultstring: 'Invalid ApiKey',
detail: { errorcode: 'oauth.v2.InvalidApiKey' }
}
}
```

Ensure that your API Project ID in `api_project_id.txt` is present and correct. See instructions above.

### `rllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>`

If you've installed Python by downloading it into a folder, find that installation folder (e.g. `/Applications/Python 3.10`). Inside the folder there should be a `Install Certificates.command` file. Run this file by double-clicking it.
Expand Down
1 change: 0 additions & 1 deletion api_project_id.txt

This file was deleted.

13 changes: 5 additions & 8 deletions get_workspace.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import fs from 'fs/promises';
* This program prints the current workspace using credentials stored in files
*/

const apiProjectIdFile = 'api_project_id.txt';
const credsFile = 'creds.json'
const aacURLFile = 'aac_url.txt'

async function main() {
const accessToken = await getAccessToken();
const apiProjectId = (await fs.readFile(apiProjectIdFile)).toString().trim();
const aacURL = (await fs.readFile(aacURLFile)).toString().trim();
console.log(await getCurrentWorkspace(aacURL, accessToken, apiProjectId));
console.log(await getCurrentWorkspace(aacURL, accessToken));
}

main();
Expand All @@ -26,13 +24,13 @@ main();
*/
async function getAccessToken() {
// Load the credentials from their JSON file
const oldCreds = JSON.parse(await fs.readFile(credsFile));
const oldCreds = JSON.parse(await fs.readFile(credsFile));

// Get the second part of the access token, which is its payload
const payload = oldCreds.access_token.split('.')[1]
const payload = oldCreds.access_token.split('.')[1]

// Decode the base64-encoded access token
const info = JSON.parse(atob(payload))
const info = JSON.parse(atob(payload))

// Create the body for the refresh request
const body = new URLSearchParams({
Expand All @@ -58,12 +56,11 @@ async function getAccessToken() {
/**
* Gets the current workspace, and returns it as an object
*/
async function getCurrentWorkspace(aacURL, accessToken, apiProjectId) {
async function getCurrentWorkspace(aacURL, accessToken) {

// These headers are necessary in every request to the AAC API
const headers = {
'Authorization': `Bearer ${accessToken}`,
'x-api-project-id': apiProjectId,
'User-Agent': 'myApp', // Describe your application here
}

Expand Down
14 changes: 3 additions & 11 deletions get_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@
This program prints the current workspace using credentials stored in a file
"""

"""
Get a new Api Project ID here: https://us1.alteryxcloud.com/cloud-portal/library/alteryx-io
This uniquely identifies your application
"""
api_project_id_file = 'api_project_id.txt'
creds_file = 'creds.json'
aac_url_file = 'aac_url.txt'

def main():
with open(api_project_id_file) as f:
api_project_id = f.read().rstrip()
access_token = get_access_token()
with open(aac_url_file) as f:
aac_url = f.read().rstrip()
print(get_current_workspace(aac_url, access_token, api_project_id))
print(get_current_workspace(aac_url, access_token))

def get_access_token():
"""
Expand Down Expand Up @@ -62,15 +55,14 @@ def get_access_token():

return new_creds['access_token']

def get_current_workspace(aac_url, access_token, api_project_id):
def get_current_workspace(aac_url, access_token):
"""
Given an access token and api project id,
Given an access token,
Gets the current workspace, and returns it as an object
"""
# These headers are necessary in every request to the AAC API
headers = {
'Authorization': f'Bearer {access_token}',
'x-api-project-id': api_project_id,
'User-Agent': 'my_app', # Descirbe your application here
}

Expand Down
8 changes: 2 additions & 6 deletions get_workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

# Requirements: jq, curl

api_project_id_file="api_project_id.txt"
creds_file="creds.json"
aac_url_file="aac_url.txt"

# Main function
main() {
api_project_id=$(cat $api_project_id_file | xargs)
access_token=$(get_access_token)
aac_url=$(cat $aac_url_file | xargs)
echo $(get_current_workspace "$access_token" "$api_project_id" "$aac_url")
echo $(get_current_workspace "$access_token" "$aac_url")
}

# Function to get the access token (with refresh logic)
Expand Down Expand Up @@ -49,13 +47,11 @@ get_access_token() {
get_current_workspace() {

access_token="$1"
api_project_id="$2"
aac_url="$3"
aac_url="$2"

# Make the request to get the current workspace using curl
response=$(curl -s -X GET "$aac_url/iam/v1/workspaces/current" \
-H "Authorization: Bearer $access_token" \
-H "x-api-project-id: $api_project_id" \
-H "User-Agent: myApp") # Describe your application here

# Output the response (current workspace)
Expand Down