1

Another noobie question. I am trying to authenticate a REST request using Python.

I import requests and fire off a command like this:

r=requests.post('https://www.exacttargetapis.com/hub/v1/campaigns', 'Content-Type: application/json{"clientId": "xx","clientSecret": "xx"}')

I get status_code 401. This tells me the URL is good and so i the request but the authorisation is not.

I have seen a few scripts that import urllib2 and use authentication this way, but as a total beginner to Python i'm not sure how to apply this.

Could anyone show me a templated approach to this and deconstruct and use ? I would be super greateful.

thanks,

2 Answers 2

1

go it. This is what i was trying to do.

#!/usr/bin/python

import requests
headers = {'Content-Type': 'application/json',}
data = '{"clientId": "xxxxxx","clientSecret": "xxxxxx"}'

access_token=requests.post('https://auth.exacttargetapis.com/v1/requestToken', headers=headers, data=data)

print access_token.text()
1
  • 1
    Well i was right that you are pointing to wrong URL ;) no worries.+1 for your question and answer.
    – Mr.Frodo
    Commented May 5, 2016 at 17:21
0

I think the issue here is that you have to first obtain access token with the help of client id and client secret.

Then use that access token in further api requests.

To obtain access token:

Endpoint URL: https://auth.exacttargetapis.com/v1/requestToken

Content-Type: application/json

Body:

{ "clientId": "pass your client id here",

"clientSecret": "pass your client secret here"

}

Request Method: POST

Response will be quite like this:

{ "accessToken": "YOUR_ACCESS_TOKEN" "expiresIn": 3600 }

then use this access token in futher requests:

3
  • Thank you, but how would i enter this in a Python interpreter ?
    – mok
    Commented May 5, 2016 at 11:46
  • I'm also not very familiar with python but from your post method i can say you should change the URL to requests.post('https://auth.exacttargetapis.com/v1/requestToken', 'Content-Type: application/json{"clientId": "xx","clientSecret": "xx"}')
    – Mr.Frodo
    Commented May 5, 2016 at 11:51
  • Thank you. I'm sure i'm on the right track. Unfortuntately your example returns error code 400
    – mok
    Commented May 5, 2016 at 11:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .