Python Code Example for Encoding a JWT

This Python code example encodes a JWT based on your client ID, username, and private key. It then issues a request to the /services/oauth2/token endpoint, passing the JWT in the body of the request. The resulting output contains the bearer token, which you use to authenticate subsequent requests to the API.

To run this example, install the requests library and the PyJWT library with added cryptography support. You can install these libraries using pip.

Next, create an environment variable called CLIENTID_DC that contains your client ID (also referred to as your consumer key), and create another environment variable called USER_DC that contains your user ID.

Finally, change the value of the keyFile variable in the main function to refer to your RSA private key.

If the request is successful, the response object includes the access token.