Change path in simple-salesforce library

Question:

I am trying to get a report I created on SalesForce via simple_salesforce library in python. I am able to connect successfully. However, I get invalid session id error, because the link is wrong, that is created by simple_salesforce. The url I am trying to get is different from what simple_salesforce is searching (which is given in the error below).

The link I am trying to get is : "https://gkg-mfsa.lightning.force.com/lightning/r/Report/00O9N000000JwK2UAK/view?queryScope=userFolders"

But the link simple_salesforce is searching is : "https://gkg-mfsa.my.salesforce.com/services/data/v42.0/lightning/r/Report/00O9N000000JwK2UAK/view?queryScope=userFolders" (as given in the error)

How can I get simple_salesforce library to search for the link I am trying to get instead of what it looks for.

from simple_salesforce import Salesforce


sf = Salesforce(username='myUserName', 
                password='myPassword',
                security_token='mySecurityToken',
               instance_url = "")

report_id = 'myreportId'

sf.restful("lightning/r/Report/ + reportId + /view?queryScope=userFolders")

output

SalesforceExpiredSession: Expired session for https://gkg-mfsa.my.salesforce.com/services/data/v42.0/lightning/r/Report/00O9N000000JwK2UAK/view?queryScope=userFolders. Response content: [{'message': 'This session is not valid for use with the REST API', 'errorCode': 'INVALID_SESSION_ID'}]


Asked By: sara

||

Answers:

Grab the session id and base endpoint from successful login call

session_id, instance = SalesforceLogin(
    username='[email protected]',
    password='password',
    security_token='token')

And then run a REST request manually. But you’ll have to pass the session id as a cookie, not as a "Authorisation Bearer <session_id>" http header.

There’s an example in
https://github.com/simple-salesforce/simple-salesforce/issues/584

And one of my old answers (showing raw http but still, should give you an idea) https://stackoverflow.com/a/56162619/313628, https://stackoverflow.com/a/57745683/313628

Answered By: eyescream