Get an access token
In order to make the HTTP request to the Auth0/oauth/token
API endpoint we will use the libraries json
, urllib
and urllib2
.
This is our sample implementation:
access_token
variable and run the process using python cron.py
.
Invoke the API
The steps we follow in our implementation are:- Build a JSON object containing timesheet data and assign it to a
timesheet
variable. - Add the API URL and the
timesheet
variable contents to the request body usingurllib2.Request
. - Add the
Authorization
header to the request. - Set the
Content-Type
header toapplication/json
. - Invoke the API using
urllib2.urlopen
and add some error handling. Retrieve the response usingjson.loads
and print it in the console.
python cron.py
.
That’s it! You are done!