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
timesheetvariable. - Add the API URL and the
timesheetvariable contents to the request body usingurllib2.Request. - Add the
Authorizationheader to the request. - Set the
Content-Typeheader toapplication/json. - Invoke the API using
urllib2.urlopenand add some error handling. Retrieve the response usingjson.loadsand print it in the console.
python cron.py.
That’s it! You are done!