Developer

Basic API Requests for v2

This guide assumes you have obtained an access token from an authorized user. You can obtain an access token by completing the OAuth flow (see the Application Authorization guide).

This page contains the details for v2 REST APIs. You can also see the guide for v3 REST APIs and for v3 GraphQL APIs.

The Base URL

All API endpoints share the same base URL whether you are trying to access them through REST or GraphQL methods:


Authorization Header

All operations whether REST or GraphQL require an Authorization header based on the access tokens received from the OAuth flow. The value of this header should match the format of Bearer <access-token>.

Implementation using REST APIs

Assembling a REST Request

URL

A request URL is assembled from the base URL and the path information for an operation as found in the reference. For example, Add a User to an Organization is an operation with path /organizations/<organizationId>/users. Combining this path with the base URL gives us a request URL of:


Parameters

The path for the operation above, like many in the Bluescape API, contains a parameter. Adding a user to an organization requires we identify the organization to which the new user should be invited. To finish preparing this request URL, we must replace <organizationId> with a valid organization ID, such as one obtained from the List a User's Organizations operation. Replacing the parameter placeholder with a sample organization ID yields a request URL of:


In addition to path parameters, some requests will have query, body and form data parameters. Reviewing the documentation for Add a User to an Organization, we see that this operation has a JSON-format body parameter, with required id, type and organizationRoleId fields. When an operation requires a body parameter, be sure to send your request with a Content-Type header of application/json. When a form data parameter is expected, be sure to send your request with a Content-Type header of multipart/form-data. A valid body for this request looks like:

{
  "id": "<SET_USER_ID>",
  "type": "<SET_MEMBER_TYPE>", #example: User
  "organizationRoleId": "<SET_ORGANIZATION_ROLE_ID>"
}

Assembled Request

Putting this all together, a request to Add a User to an Organization looks like:

curl -X POST  \
  -H 'Authorization: Bearer <SET_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "<SET_USER_ID>",
    "type": "<SET_MEMBER_TYPE>", #example: User
    "organizationRoleId": "<SET_ORGANIZATION_ROLE_ID>"
  }'

import requests
import pprint 

portal = ''
organizationId = '<SET_ORGANIZATION_ID>';
API_version = 'v2'
API_endpoint = '/' + API_version + '/organizations/' + organizationId + '/users'
token = '<SET_TOKEN>';
data_load = {
  "id": "<SET_USER_ID>",
  "type": "<SET_MEMBER_TYPE>", #example: User
  "organizationRoleId": "<SET_ORGANIZATION_ROLE_ID>"
}

the_request = requests.post(
    portal+API_endpoint,
    headers={"Authorization": "Bearer " + token,
            "Content-Type": "application/json"
            },
    json=data_load
)

json_response = the_request.json()
pprint.pprint(json_response)


If you have any questions or comments, please contact us at Bluescape support.