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,

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()
| improve this answer | |
  • 1
    Well i was right that you are pointing to wrong URL ;) no worries.+1 for your question and answer. – Mr.Frodo May 5 '16 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:

| improve this answer | |
  • Thank you, but how would i enter this in a Python interpreter ? – mok May 5 '16 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 May 5 '16 at 11:51
  • Thank you. I'm sure i'm on the right track. Unfortuntately your example returns error code 400 – mok May 5 '16 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.