Using API Tokens

API tokens can be used with both the REST and GraphQL APIs. To use the token, it must be supplied as part of the Authorization header made as part of the HTTP request:

http
Authorization Bearer pHUw1oLASALFmt2ppNvwCR0Meo2nHQ15~ECViF0Ce95uIqFGSSatjKWX71EOzvkpVGSuc3zGYqJgR

For example, the following Python script will create a new repository

python
import requests
import json 
 
query = """mutation { 
  createRepository(name : "SampleRepository") { 
    id 
  } 
} 
""" 
 
headers = {"Authorization":
"Bearer pHUw1oLASALFmt2ppNvwCR0Meo2nHQ15~ECViF0Ce95uIqFGSSatjKWX71EOzvkpVGSuc3zGYqJgR"}
 
url = 'http://example.com:8080/graphql' 
r = requests.post(url, headers=headers, json={'query': query})

print(r.status_code) 
print(r.text) 
 
json_data = json.loads(r.text) 
 
print(json_data)

For more information on executing API queries, see Application Programming Interfaces (APIs).