Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

sipgate logo python Personal Access Token example

To demonstrate how to authenticate against the sipgate REST API using HTTP Basic Auth, we query the /account endpoint which provides basic account information.

For further information regarding the sipgate REST API please visit

For more information on how to create a token, visit


  • python3
  • pip3

How To Use

Navigate to the project's root directory.

Install dependencies:

$ pip3 install -r requirements.txt

Create the .env file by copying the .env.example. Set the values according to the comment above each variable.

The token should have the account:read scope. For more information about personal access tokens visit

Run the application:

$ python3

How It Works

Request parameters like url and headers are defined as follows:

base_url = ''

credentials = (token_id + ':' + token).encode('utf-8')
base64_encoded_credentials = base64.b64encode(credentials).decode('utf-8')

headers = {
    'Authorization': 'Basic ' + base64_encoded_credentials

Note: Basic Auth requires the credentials to be Base64-encoded.
Note: The base64 encoder requires byte-like-objects. We use .encode('utf-8') and .decode('utf-8') to convert strings to byte-like-objects and vice versa.

If OAuth should be used for Authorization instead of Basic Auth we do not suply the auth object in the request options. Instead we set the authorization header to Bearer followed by a space and the access token: Authorization: `Bearer ${accessToken}`,. For an example application interacting with the sipgate API using OAuth see our python OAuth example.

We use the python package 'requests' for request generation and execution. The requested URL consists of the base url defined above and the endpoint /account. This example prints the status code and response body to the console.

response = requests.get(base_url + '/account', headers=headers)

print('Status:', response.status_code)
print('Body:', response.content.decode("utf-8"))

Common Issues

HTTP Errors

reason errorcode
token_id and/or token are wrong 401
credentials not Base64-encoded 401
wrong REST API endpoint 404
wrong request method 405


Contact Us

Please let us know how we can improve this example. If you have a specific feature request or found a bug, please use Issues or fork this repository and send a pull request with your improvements.


This project is licensed under The Unlicense (see LICENSE file).

External Libraries

This code uses the following external libraries | @sipgateio | API-doc


A demonstration on how to authenticate yourself against the sipgate REST API using HTTP Basic Auth, which returns basic account information.







No releases published


No packages published