Objective: get a list of all Workspaces you can access. You do not need to know your userId to perform this operation. From this list you can retrieve the workspace IDs to use on other APIs that require you to have the Workspace ID. This is a good test to verify the functionality of your Access Token.
This page contains the implementation details for v3 REST APIs and for v3 GraphQL APIs. You can also see the example for v2 REST APIs.
All API endpoints share the same base URL:
https://api.apps.us.bluescape.com
After you receive the authentication token, you can get a list of all the workspaces you can access.
Implementation using REST APIs
Endpoint | /v3/users/me/workspaces |
---|---|
Method | GET |
Comments | You do not need to know the userId to get this list of workspaces of the user. |
Code sample
See below code samples in cURL, Node.js, and Python.
cURL
curl --location --request GET 'https://api.apps.us.bluescape.com/v3/users/me/workspaces' \
--header 'Authorization: Bearer <SET_TOKEN>' ```
Node.js
// NodeJS
var axios = require('axios');
/*
How to run:
node this_script_name.js
Requires "axios" module (0.19.0), run:
npm install axios
website: https://github.com/axios/axios
*/
const token = '<SET_TOKEN>';
const portal = 'https://api.apps.us.bluescape.com';
const api_version = 'v3';
const api_endpoint = '/users/me/workspaces';
request_values = {
method: 'GET',
url: portal + '/' + api_version + api_endpoint,
headers : {
'Authorization': "Bearer " + token,
'Content-Type' : 'application/json'
}
};
axios(request_values)
.then(function (response) {
if (response.status == 200)
{
console.log("Success");
console.log(response.data);
}
})
.catch (function (error) {
console.log('Error: ' + error.message);
});
Python
# Python Code (python 3.5+)
import requests
import pprint
'''
Required modules:
requests 2.22.0
'''
# Get the list of workspaces the user account associates to the Authentication Token can access
token = '<SET_TOKEN>'
if __name__ == "__main__":
portal = "https://api.apps.us.bluescape.com"
# Get all the workspaces for your user
API_version = 'v3'
API_endpoint = '/' + API_version + '/users/me/workspaces'
the_request = requests.get(
portal + API_endpoint,
headers={"Authorization": "Bearer " + token}
)
# format answer to json
json_response = the_request.json()
# By default we get the first 25 workspaces
# added to format display of json output
pprint.pprint(json_response)
OUTPUT
What you should get: JSON with the list of the first 25 workspaces your user has access to.
Element | Json | Comments |
---|---|---|
Workspace ID | [‘workspaces’][N][‘id’] | where N is the N-th workspace in the list. |
Workspace name | [‘workspaces’][N][‘name’] | where N is the N-th workspace in the list. |
Output Json sample
{
"workspaces": [
{
"id": "jb37zzmsAvin16ti2A-9",
"name": "test-workspace",
"description": "",
"isPublic": true,
"defaultRoleId": "JuTasisnG_LWZ6VyE-d5",
"organizationId": "ugNVBeehXBSc8wV3BzTG",
"contentUpdatedAt": null,
"createdAt": "2021-02-02T00:30:38.000Z",
"updatedAt": "2021-02-25T19:51:12.000Z"
}
],
"prev": null,
"next": null
}
Implementation using GraphQL APIs
Query | me |
---|---|
Comments | You do not need to know the userId to get this list of workspaces of the user. |
Example Query:
query getMyWorkspaces{
me {
workspaces {
totalItems
results {
name
description
isPublic
owner {email firstName lastName}
}
}
}
}
Code sample
See below for full code examples of this implementation in cURL, Node.js, and Python.
cURL
curl --location --request POST 'https://api.apps.us.bluescape.com/v3/graphql' \
--header 'Authorization: Bearer <SET_TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query getMyWorkspaces{\n me {\n workspaces {\n totalItems\n results {\n name\n description\n isPublic\n owner {email firstName lastName}\n }\n }\n }\n}","variables":{}}'
Node.js
const axios = require('axios');
const url = "https://api.apps.us.bluescape.com/v3/graphql"
const token = "<SET_TOKEN>"
const query = `query getMyWorkspaces{
me {
workspaces {
totalItems
results {
name
description
isPublic
owner {email firstName lastName}
}
}
}
}`
const getWorkspaces = async () => {
try {
const response = await axios.post(url,
{query: query},
{headers: {"Authorization": "Bearer " + token}})
answerData = JSON.stringify(response.data);
console.log(answerData);
return response
}
catch(error) {
console.error(error)
}
}
getWorkspaces();
Python
import requests
import pprint
url = "https://api.apps.us.bluescape.com/v3/graphql"
token = "<SET_TOKEN>"
query = """
query getMyWorkspaces{
me {
workspaces {
totalItems
results {
name
description
isPublic
owner {email firstName lastName}
}
}
}
}
"""
def makeQuery():
response = requests.post(url,
headers={"Authorization": "Bearer " + token
},
json={'query': query})
return response.json()
if __name__ == "__main__":
response = makeQuery()
pprint.pprint(response)
Output
{
"data": {
"me": {
"workspaces": {
"totalItems": 2,
"results": [
{
"name": "workspace 1",
"description": "",
"isPublic": true,
"owner": {
"email": "littlejohnny@someplace.org",
"firstName": "Little",
"lastName": "Johnny"
}
},
{
"name": "workspace 2 - meetings",
"description": "For our meetings",
"isPublic": true,
"owner": {
"email": "jopsephusmiller@someplace.org",
"firstName": "Josephus",
"lastName": "Miller"
}
}
}
}
}
}
Where to Next?
- Get the list of your workspaces for v2
- Bluescape API Guides
- Bluescape API Overview
- Latest Developer topics
Not what you were looking for? Reply below or Search the community and discover more Bluescape.