Python Connector for Salesforce CDP
Project description
salesforce-cdp-connector
A readonly CDP client for Python. This can be used to execute queries against CDP and load the data into python.
Usage
Installation
Install the package from Pypi using the command
pip install salesforce-cdp-connector
Quick Start
We have to create an instance of the SalesforceCDPConnection to connect to CDP.
The object can be created as follows:
Using Username and Password
from salesforcecdpconnector.connection import SalesforceCDPConnection
conn = SalesforceCDPConnection(
'login_url',
'user_name',
'password',
'client_id',
'client_secret'
)
Using OAuth Tokens
from salesforcecdpconnector.connection import SalesforceCDPConnection
conn = SalesforceCDPConnection(login_url,
client_id='<client_id>',
client_secret='<client_secret>',
core_token='<core token>'
refresh_token='<refresh_token>'
)
Once the connection object is created the queries can be executed using cursor as follows
cur = conn.cursor()
cur.execute('<query>')
results = cur.fetchall()
The query results can also be directly extracted as a pandas dataframe
dataframe = conn.get_pandas_dataframe('<query>')
Creating a connected App
- Log in to salesforce as an admin. In the top right corner, click on the gear icon and go to step
- In the left hand side, under Platform Tools, go to Apps > App Manager
- Click on New Connected App
- Fill in the required Basic Information fields.
- Under API (Enable OAuth Settings)
- Click on the checkbox to Enable OAuth Settings.
- Provide a callback URL.
- In the Selected OAuth Scopes, make sure that refresh_token, api, cdp_query_api, cdp_profile_api is selected.
- Click on Save to save the connected app
- From the page that opens up, click on the Manage Consumer Details to find your client id and client secret
Fetching Refresh Token
-
From the connected app, note down the below details:
- Client Id
- Client Secret
- Callback URL
-
Obtain the code
- From browser, go to the below url.
<LOGIN_URL>/services/oauth2/authorize?response_type=code&client_id=<client_id>&redirect_uri=<callback_url>
- This will redirect you to the callback url. The redirected url will be of the form
<callback url>?code=<CODE>
- Extract the CODE from the address bar to be used in next step. Check the network tab of browser if the addressbar doesn't show this.
-
Get core and refresh tokens
- Make a post call using curl or postman to the below url using the code retrieved in previous step.
<LOGIN_URL>/services/oauth2/token?code=<CODE>&grant_type=authorization_code&client_id=<clientId>&client_secret=<clientSecret>&redirect_uri=<callback_uri>
- The response to the above post call will be a json with access_token and refresh_token
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for salesforce-cdp-connector-1.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddf2646f06ede7ec869609a8a1eeabd976d5498a34e85164ef09ace371f2c5cc |
|
MD5 | a3e305ced3b134138a07dc6f2b29a994 |
|
BLAKE2b-256 | 870b56825c7012ed9fc596e98656b3fc90988a3e1c2c342714cc651b01092bb6 |
Close
Hashes for salesforce_cdp_connector-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9414f5fe00ffbe5bcd360ab3e809b1dad03e8f90e07a93424873d095370220cd |
|
MD5 | a14f51b0b1ce3141d160ee0900f1a0c4 |
|
BLAKE2b-256 | faa62326e6a1615ad7fdcf373f62bb8b999f870f9900942b22a74c93dd4dee5f |