Skip to main content

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 JWT

from salesforcecdpconnector.connection import SalesforceCDPConnection

fd = open('./salesforce.key');
your_key = fd.read()

conn = SalesforceCDPConnection(login_url, 
       client_id='<client_id>', 
       username='<username>', 
       private_key=your_key
   )

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

  1. Log in to salesforce as an admin. In the top right corner, click on the gear icon and go to step
  2. In the left hand side, under Platform Tools, go to Apps > App Manager
  3. Click on New Connected App
  4. Fill in the required Basic Information fields.
  5. Under API (Enable OAuth Settings)
    1. Click on the checkbox to Enable OAuth Settings.
    2. Provide a callback URL.
    3. In the Selected OAuth Scopes, make sure that refresh_token, api, cdp_query_api, cdp_profile_api is selected.
    4. Click on Save to save the connected app
  6. From the page that opens up, click on the Manage Consumer Details to find your client id and client secret

Fetching Refresh Token

  1. From the connected app, note down the below details:

    • Client Id
    • Client Secret
    • Callback URL
  2. Obtain the code

    1. From browser, go to the below url.
    <LOGIN_URL>/services/oauth2/authorize?response_type=code&client_id=<client_id>&redirect_uri=<callback_url>
    
    1. This will redirect you to the callback url. The redirected url will be of the form <callback url>?code=<CODE>
    2. 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.
  3. Get core and refresh tokens

    1. 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>
    
    1. The response to the above post call will be a json with access_token and refresh_token

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

salesforce-cdp-connector-1.0.15.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

salesforce_cdp_connector-1.0.15-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file salesforce-cdp-connector-1.0.15.tar.gz.

File metadata

File hashes

Hashes for salesforce-cdp-connector-1.0.15.tar.gz
Algorithm Hash digest
SHA256 631bd5e05c320b14932030aec303db93e8646e375d1202cf344a3ec529a3a896
MD5 8858cfb22ca7d6ba8ec49c94ea52f101
BLAKE2b-256 79c6ce281ee870ea1cb2fa26b166f12c913c6746c4874acbebb0eca922ab4845

See more details on using hashes here.

File details

Details for the file salesforce_cdp_connector-1.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for salesforce_cdp_connector-1.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 c03054c5b43145d7ed10084ce1f5551ef862e8a31a5b5b81f2630cb69dec0b79
MD5 d27c9aa34ab2c3406b76e02692fd6e9b
BLAKE2b-256 549c6faa6fe8665e5913ebde0a627890d6aff33a603590dd81522bbf745cb8b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page