Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)
edited by

I am new to sfdc. I have reported already created by the user . I would like to use python to dump the data of the report into CSV/excel file. I see there are 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)
edited by

You can set up the API using the following sample code, this shouldn't give an error:

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 can be read with the csvmodule.

Now, take data into pandas from there, therefore the function name and import pandas. I removed the rest of the function where it puts the data into a DataFrame.

To learn in-depth about Salesforce, sign up for an industry-based Salesforce Certification!

Related questions

Browse Categories

...