0 votes
1 view
in Salesforce by (11.9k points)

I am new to sfdc. I have already created the user. I would like to use python to dump the data of the report into csv/excel file. I see there is a couple of python packages for that. But my code gives an error:

from simple_salesforce import Salesforce

sf = Salesforce(instance_url='https://cs1.salesforce.com', session_id='')

sf = Salesforce(password='xxxxxx', username='xxxxx', organizationId='xxxxx')

Can i have the basic steps for setting up the API and some example code

1 Answer

0 votes
by (32.1k points)

Try the following code. This should work:

import requests

import csv

from simple_salesforce import Salesforce

import pandas as pd

sf = Salesforce(username=your_username, password=your_password, security_token = your_token)

login_data = {'username': your_username, 'password': your_password_plus_your_token}

with requests.session() as s:

    d = s.get("https://your_instance.salesforce.com/{}?export=1&enc=UTF-8&xf=csv".format(reportid), headers=sf.headers, cookies={'sid': sf.session_id})


d.content contains a string of comma-separated values which you can read with the csvmodule.

I am taking the data into pandas from there, henceforth the function name and import pandas. So, I discarded the rest of the function where it puts the data into a DataFrame, but if you're interested in how that's done let me know.

To learn in-depth about Workflow in Salesforce, sign up for an industry based Salesforce Course.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !