Salesforce REST API Connector via JSLOver the past few months, I've received a few requests from SEs asking how to query Salesforce data through JMP. The attached files provide the scripting framework that I use to connect JMP to Salesforce and query data. Below is a description of the attached scripts, as well as the process on how to use them to successfully set everything up:
- Generate Refresh Token.jsl
- This script should only be run ONCE!!! Once a refresh token is generated, it will persist indefinitely. Rerunning the script will reset the refresh token, which will affect all future steps.
- There are 2 fields that need to be entered in this script: client id and client secret
- These values need to be obtained from within Salesforce.
- These values will need to be entered in the correct positions in lines 13, 19, and 20 in the script.
- Run the script after the client id and client secret are entered, and the "rtoken" field will be displayed in the log. Save this value in a safe place - this is the refresh token that has been generated. As per above, this token will persist indefinitely, so do not rerun this script again unless you need a new refresh token.
- Generate Auth Fields.jsl
- Now that the refresh token has been obtained, the access token needed to access data in Salesforce can be obtained. The function in this script generates the access token and other fields necessary to run a query, returning these values in the form of an Associative Array. There are 3 values that need to be input into this function (listed in the order that they should appear as inputs):
- rtoken - this is the refresh token generated from the above script
- client_id - this is the client id taken from within Salesforce
- client_secret - this is the client secret taken from within Salesforce
- Below are the keys and corresponding values that get returned in the Associative Array generated by this function:
- client_id - this is the client id that was initially input
- access_token - this is the access token needed to access data in Salesforce
- instance_url - this is the URL of your organization's Salesforce instance,
- Query Formula String.jsl
- This script contains the function needed to query data from Salesforce. The function has 5 inputs (listed in order of input below), and returns a data table.
- st - this is the SOQL query string that specifies the data that is being queried. Workbench is a great resource for generating SOQL queries.
- access_token - this should be taken from the Associative Array generated in the above script.
- client_id - this should be taken from the Associative Array generated in the above script.
- instance_url - this should be taken from the Associative Array generated in the above script.
- tablename - this should be set as the desired table name for the data table generated by this function. If left blank, it will automatically name the generated table as "Salesforce Generated Table".
- Example Query.jsl
- This script contains an example of how to use the "Generate Auth Fields.jsl" and "Query Formula String.jsl" scripts to generate a table of Salesforce data. In order for this script to work, the client will have to enter their specialized inputs in the Generate Auth Fields function.
Information ReferencesScripts