Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is using the access_token from a login/password authenticated response.

Firstly do a login to get the access_token.

Getting Access Token using Curl

Code Block
languagebash
curl --location --request POST 'http://127.0.0.1:5000/api/v1/login' \
--header 'Content-Type: application/json' \
--data-raw '{"username":"<your_username>","password":"<your_password"}'

Getting Access Token using Python

Code Block
languagepy
import requests
import json

ACCESS_TOKEN_IDENTIFIER = "access_token"

url = "http://127.0.0.1:5000/api/v1/login"

payload = json.dumps({
  "username": "<username>",
  "password": "<password>"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

json_response = json.loads(response.text)

if "ACCESS_TOKEN_IDENTIFIER" in json_response:
    access_token = json_response["ACCESS_TOKEN_IDENTIFIER"]

Then the response will have an access token, use this in the next requests.

Code Block
languagejson
{
    "access_token": "<access token>",
    "id": 6000,
    "firstname": "Joe",
    "lastname": "Bloggs",
    "nickname": "Joey",
    "roles": "admin"
}

Code Examples using Access Token to call API

Using Curl

Code Block
languagebash
curl --location --request GET 'https://api.ctci.ai/api/v1/cewl' \
--header 'Authorization: Bearer <Put access_token here><access token>'

Using Python

Code Block
languagepy
import requests

url = "https://api.ctci.ai/api/v1/cewl"

payload={}
headers = {
  'Authorization': 'Bearer <Put access_token here>'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

...