Getting an Access Token
This guide covers three OAuth 2.0 grant types: Authorization Code Grant, Password Grant, and Personal Access Tokens.
Overview
Client Application
Creating a Client ApplicationChoose Your Tutorial
Step 1: Install Necessary Python Libraries
pip install requests oauthlibStep 2: Set Up Your Client Application
Step 3: Use the Correct Grant Type
Authorization Code
import requests
from oauthlib.oauth2 import WebApplicationClient
# Initialize the OAuth client
client = WebApplicationClient(client_id='<your-client-id>')
# Generate the authorization URL
auth_url, _ = client.prepare_request_uri(
'https://<your-instance>.processmaker.net/oauth/authorize',
redirect_uri='<your-redirect-uri>',
scope='<your-scope>',
)
print(f'Please go to the following URL and authorize the app: {auth_url}')
# After the user has authorized the app, they will be redirected to the redirect URI
# with a code in the query string. Paste that code here.
code = input('Enter the authorization code: ')
# Exchange the authorization code for an access token
token_url = 'https://<your-instance>.processmaker.net/oauth/token'
token_data = client.prepare_request_body(
code=code,
client_id='<your-client-id>',
client_secret='<your-client-secret>',
redirect_uri='<your-redirect-uri>',
)
response = requests.post(token_url, data=token_data)
token_info = response.json()
print(f'Access token: {token_info["access_token"]}')Password
Personal Access Tokens
Step 4: Making API Requests
Last updated