I need to use an API that makes cURL calls. API shown here: https://www.pivotaltracker.com/help/api/rest/v5. I am coding in Python 2.7 and downloaded the Requests module to use for the cURL calls, however I'm not exactly sure how to do this. This is what I have so far:
import requests
username = 'my_username'
password = 'my_password'
url = 'https://www.pivotaltracker.com/n/projects/my_project_number'
r = requests.get(url, auth=(username, password))
Now that I have the response r, what do I do with it to make the cURL calls in order to use the API functions, such as the GET /projects/{project_id}/epics/{epic_id} function. The cURL call for this function is:
export TOKEN='your Pivotal Tracker API token'
export PROJECT_ID=99
curl -X GET -H "X-TrackerToken: $TOKEN" "https://www.pivotaltracker.com/services/v5/projects/$PROJECT_ID/epics/4"
Thanks for any help you can provide!
EDIT (thanks to @Rob Watts) Now this is my code:
import requests
username = 'my_username'
password = 'my_password'
url = 'https://www.pivotaltracker.com/services/v5/me'
r = requests.get(url, auth=(username, password))
response_json = r.json()
token = response_json['api_token']
project_id = 'my_project_id'
url = 'https://www.pivotaltracker.com/services/v5/projects/{}/epics/1'
r = requests.get(url.format(project_id), headers={'X-TrackerToken':token})
print r.text
But it still isn't working. This is the output:
{
"code": "unfound_resource",
"kind": "error",
"error": "The object you tried to access could not be found. It may have been removed by another user, you may be using the ID of another object type, or you may be trying to access a sub-resource at the wrong point in a tree."
}
But per the documentation, I expect something like this:
{
"created_at": "2014-08-26T12:00:00Z",
"description": "Identify the systems and eliminate the rebel scum.",
"id": 1,
...
}