hide's memo
7 Apr, 2022

How to get a Refreshtoken. (Refresh token is valid for 365 days) Salesforce.

[日本語]

This is a sample for getting the refresh token from saleforce.

(1)Login Salesforce

(2)Change Classc UI (I am not sure hot to do this by Lightning Expreience)

(3)”Setup” -> “Build – Create – Apps” -> Click “Create Apps New” Button.

(4)Input parameters as brlow.

 

(4.1)Connected App Name …. “sample”

(4.2)API Name ….. “sample”

(4.3)Contact Email …. your email address.

(4.4)Check “Enable OAuth Settings”

(4.5)Set “http://localhost” in “Calllback URL”

(4.6)Selected OAuth Scope … “Full access” + “Perform requests at any time(refresh_token,offline_access)..
warning!! this is sample. you should check this permission carefully.

(4.7)Set your salesforce address in “Start URL”

then, “Save” and Copy next form’s “Consumer Key” and “Consumer Secret”

 

(5)”Setup” -> “Administer – Manage Apps – Connected Apps”
(5.2)select “sample”

(5.1)”Edit Policies”

(5.2)”Refresh token policy” : Set “Expire refresh token after 365 days.”

(6)Input the url bellow on the web broweer which you are currently using(currently accsssing the salesforce(having web session))

https://****.my.salesforce.com/services/oauth2/authorize?response_type=code&client_id=****&redirect_uri=http%3A%2F%2Flocalhost

* Set your salesforce server name.
* client_id …. your “consumer key”

(6.1)You will be confirmed as below message and select “Allow”

 

(7)you will be redirected to the following url.
http://localhost/?code=*****
so, save the code.

(8)write a shell as below.

#!/bin/sh
CLIENT_ID="consumer key"
CLIENT_SECRET="consumer secret"
SERVER="yourserver****.my.salesforce.com"
CODE="the code you got at (7)"

#GET REFRESH TOKEN
curl -X POST https://$SERVER/services/oauth2/token -d "grant_type=authorization_code" -d "client_id=$CLIENT_ID" -d "client_secret=$CLIENT_SECRET" -d "code=$CODE" -d "redirect_uri=http%3A%2F%2Flocalhost"

 

execute the shell above, you can get the response as below.

{"access_token":"***","refresh_token":"***","signature":"****","scope":"refresh_token full","id_token":"","instance_url":"https://***.my.salesforce.com","id":"https://login.salesforce.com/id/******","token_type":"Bearer","issued_at":"*****"}

 

5 Mar, 2022

Get Record with using REST-API(SELECT) Salesforce

[japanese(日本語)]

This is sample for getting record from Salesforce with using REST-API(SELECT).

Get record from User Object.Name with LastUpdated > 2022/3/5 15:03:00(JST).

The “$ACCESS” in the below sample is  a access token that you can get with using this method(Get data from Salesforce using curl Salseforce).

DATE="2020-03-05T15%3A03%3A00%2B09%3A00"
curl -H "Authorization: Bearer $ACCESS" "https://$SERVER/services/data/v50.0/query/?q=SELECT+Name+from+User+where+LastModifiedDate%3E$DATE"

 

Get Name,Fax,Division and Signature.

DATE="2020-03-05T15%3A03%3A00%2B09%3A00"
curl -H "Authorization: Bearer $ACCESS" "https://$SERVER/services/data/v50.0/query/?q=SELECT+NAME%2CFax%2CDivision%2CSignature+from+User+where+LastModifiedDate%3E$DATE"
19 Feb, 2022

Get data from Salesforce using curl Salseforce

[japanese(日本語)]

1.Using refreshtoken

#!/bin/sh

MY_INSTANCE="miura2-dev-ed"
CLIENT_ID="*** your client id ***"
CLIENT_SECRET="*** your client secret ***"
REFRESH_TOKEN="*** your refresh token ***"

#----------------------------------------------
# Get Access token from Refresh token.
#----------------------------------------------
RESULT=`curl -X POST https://$MY_INSTANCE.my.salesforce.com/services/oauth2/token -d "grant_type=refresh_token" -d "client_id=$CLIENT_ID" -d "client_secret=$CLIENT_SECRET" -d "refresh_token=$REFRESH_TOKEN"`

ACCESS=`echo $RESULT | awk 'BEGIN{FS="access_token\":"}{print $2}' |awk 'BEGIN{FS=","}{print $1}' | sed -s 's/\"//g'`

#----------------------------------------------
#Get data using Access token
#----------------------------------------------
curl -s https://$MY_INSTANCE.my.salesforce.com/services/data/v52.0/sobjects/Account -H "Authorization: Bearer $ACCESS" -H "Content-type: application/json"

 

How to get a Refreshtoken. (Refresh token is valid for 365 days) Salesforce.