[Python] FIXED - Interacting With Salesforce Rest API Through Python

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    Super simple fix detailed in this video by a glorious man: link

    example code for fix:

    from simple_saleforce import Salesforce
    import pandas as pd

    uname = 'username'
    pswd = 'passsword'
    st = 'security_token'

    sf = Salesforce(username=uname, password=pswd, security_token=st)
    response = sf.query('Whatever Query You Need in SOQL Format')
    df=pd.DataFrame(response['records'])


    then format to your needs. I should have read the documentation more in depth Simple_Salesforce is indeed the simplest way of interacting with Salesforce.

    Disregard my rambling:

    So I have written a program which process various files in different formats and data structures and reformats them all in a universal data structure so they can be easily uploaded into salesforce. Since I was working on just getting the data in I was doing manual batch loads and then pulling out the relevant Salesforce IDs I needed to add back in to data set to upload other subsets of the main set to populate other objects. I am very happy with how the processing has come out it is super not hard coded and allows me to process hundreds of files in different formats at once based on the naming convention of the file.

    Now that I have most of the data in Salesforce I am looking at creating an External Client App to use Rest API to perform upsert processes into some staging objects to perform some validation flows before pushing the data into the live objects. I have found this process very difficult. I think I have created the actual External Client App in Salesforce fine. I ended up enabling all of the OAuth Scopes out of desperation but it wasn't really working (i was able to get access token with only a few).

    I searched around for some established code that I could modify and reuse but none would work. I have never used an API in Salesforce and I am very much a junior developer so there is definitely something I am overlooking but I will include the script I got to work which gives me my access token but doesn't run queries successfully. It also requires me to interact through my browser which i am not super excited about. I wanted some advice if there is a better way to go about this or if I am on the right track.

    Continue reading...

Compartilhe esta Página