4

Complete noobie question here. I'm trying to access the REST API for ExactTarget to access Campaign data and open / clicks etc using Python

I have installed the FuelSDK and can perform requests such as those found on GIT here.

This post references the REST/SOAP api to connect campaigns with clickers.

Can anyone tell me how to access the REST urls in Python?

2
  • check Getting an Access Token and this Commented May 5, 2016 at 0:24
  • Sorry for the basic question. But How to i authenticate. r=requests.post('exacttargetapis.com/hub/v1/campaigns', 'Content-Type: application/json{"clientId": "XXXXX","clientSecret": "XXXX"}') returns 401 error. so i know the url is good, but i cannot authenticate ?
    – mok
    Commented May 5, 2016 at 9:44

3 Answers 3

2

Please read exacttarget api reference

You couldn't access resources without authorization. First you should request for an Access Token:

import json, requests

client_Id = "YOUR_CLIENT_ID_FROM_APP_CENTER"
client_Secret = "YOUR_CLIENT_SECRET_FROM_APP_CENTER"

payload = {
    'clientId': client_Id,
    'clientSecret': client_Secret
}

url = "https://auth.exacttargetapis.com/v1/requestToken";

r = requests.post(url,
    headers={"Content-Type":"application/json"},
    data=payload)

body = json.loads(r.content)
token = body["accessToken"]
expiresIn = body["expiresIn"]
print token

Now you can access your resources using Access Token:

url="https://www.exacttargetapis.com/hub/v1/campaigns?$page=1&$pageSize=2&$orderBy=Name ASC"

r = requests.get(url, headers = {"Authorization":"Bearer " + token})
print r.content

Before using Python, I recommend you to try Postman, it will help you to understand requests etc.

1
  • I dont have access to exacttarget , please add here errors if you have any Commented May 5, 2016 at 16:29
0

You have several options. If you absolutely want to use python, there are several libraries that can help you achieve this. two of them are simple-salesforce and Beatbox.

https://pypi.python.org/pypi/beatbox/32.1
https://pypi.python.org/pypi/simple-salesforce

here is an example using beatbox:

import beatbox

"salesforceusername and password"
username = 'yourUsername'
password = "yourPassword"
token    = 'yourToken'

svc = beatbox.PythonClient()
svc.login(username, password+token)

"""Simple SOQL query that returns all cases"""
res = svc.query("SELECT id FROM case")


print(res)

you can equally use this library to create/uptade or simply access Sobjects.

If you decide to use python, be carefull with the version you are using. I did the above using python2.7

0

You can use simple-salesforce pip install simple-salesforce

from simple_salesforce import Salesforce

email = [email protected]
password = 'your_password'
security_token = 'admlnlkrsl'

sf = Salesforce(username=email, password=password, security_token=security_token)

Where to find security token?

In SalesForce, using Lightning Theme:

  1. Click in the top right corner your profile icon -> Settings;
  2. In the tree select My Personal Information -> Reset My Security Token;
  3. Click Reset Security Token;
  4. Check your email for a new token.

You must log in to answer this question.

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