0% found this document useful (0 votes)
151 views4 pages

Salesforce API Integration Guide

The document describes the process to access Salesforce data through REST API calls. It involves first making a POST request to the authentication endpoint to get an access token. Then GET and POST requests can be made to the data endpoint to respectively retrieve and insert Salesforce records, by providing the access token in the authorization header. Sample code is provided to illustrate calling the different endpoints to get data, insert a new contact record, and the expected response formats.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views4 pages

Salesforce API Integration Guide

The document describes the process to access Salesforce data through REST API calls. It involves first making a POST request to the authentication endpoint to get an access token. Then GET and POST requests can be made to the data endpoint to respectively retrieve and insert Salesforce records, by providing the access token in the authorization header. Sample code is provided to illustrate calling the different endpoints to get data, insert a new contact record, and the expected response formats.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

To send and get through Salesforce data first need to get Security Token:

→ Following Flow will work for testing end point, user, password,client_id,client_secret given from my
demo salesforce developer org.

REST Request:
Type: POST
End Point: https://login.salesforce.com/services/oauth2/token

• Key:- username | Value:- zakir.oracle@gmail.com_demo

• Key:- password | Value:- dhaka1234yrUMeszp5LyzjwtVfPEOfyNN

• Key:- grant_type | Value:- password

• Key:- client_id | Value:-


3MVG9G9pzCUSkzZt8UkLOB4dGr0QPOYWX7TblbhRfQbi6Y2g6yPbmXRjBF3NyvyBMGJYWWmgMxeBKDsKxcoGX

• Key:- client_secret | Value:-

B3A94A1A9F1446BA05449372A6EE9F4E4C759FCB5AC73D60BC84A213D76D86E2

.Net Code Example:

var client = new RestClient("https://login.salesforce.com/services/oauth2/token");


var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded",
"username=zakir.oracle@gmail.com_demo&password=dhaka1234yrUMeszp5LyzjwtVfPEOfyNN&gran
t_type=password&client_id=3MVG9G9pzCUSkzZt8UkLOB4dGr0QPOYWX7TblbhRfQbi6Y2g6yPbmX
RjBF3NyvyBMGJYWWmgMxeBKDsKxcoGX&client_secret=B3A94A1A9F1446BA05449372A6EE9F4
E4C759FCB5AC73D60BC84A213D76D86E2", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Response JSON -1:

{
"access_token": "00D2v000000Qgog!
AQgAQNyZpx_ibpW1QN1o6ogcxNSFTTcwNhRGdtSM4Q4UbvKusv_497hgCE58cRopLtHRDrLcp0O
DweU6d6MTqqpIfbU2EsH1",
"instance_url": "https://ap15.salesforce.com",
"id": "https://login.salesforce.com/id/00D2v000000QgogEAC/0052v00000ZaebIAAR",
"token_type": "Bearer",
"issued_at": "1563188899596",
"signature": "2YzM7NuwbpwTlUK2wIZJZZlHZIdFlRpTQRE+zQJjNS0="
}

1- Get data api process :

Request :
Type: Get
End Point:
https://ap15.salesforce.com/services/data/v42.0/query/?q=SELECT+Id,Name,Phone+FROM+Contact

Or

https://ap15.salesforce.com/services/data/v42.0/sobjects/Contact/0032v00002j2oPtAAI

Header:

• Key:- Authorization | Value:- <access_token from Response JSON -1>

.Net Code Example:

var client = new RestClient("https://ap15.salesforce.com/services/data/v42.0/query/?q=SELECT%20Id


%2CName%2CPhone%20FROM%20Contact");
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("authorization", "Bearer 00D2v000000Qgog!
AQgAQNyZpx_ibpW1QN1o6ogcxNSFTTcwNhRGdtSM4Q4UbvKusv_497hgCE58cRopLtHRDrLcp0O
DweU6d6MTqqpIfbU2EsH1");
IRestResponse response = client.Execute(request);

Response JSON:

{
"totalSize": 21,
"done": true,
"records": [
{
"attributes": {
"type": "Contact",
"url": "/services/data/v42.0/sobjects/Contact/0032v00002j2oPrAAI"
},
"Id": "0032v00002j2oPrAAI",
"Name": "Rose Gonzalez",
"Phone": "(512) 757-6000"
},
……
…..

2-Send data api process:

Request :
Type: POST
End Point:

https://ap15.salesforce.com/services/data/v42.0/sobjects/Contact/

Header:

• Key:- Authorization | Value:- <access_token from Response JSON -1>

Request/Body JSON example:


{
"LastName" : "Logistics and Transport",
"Phone" : "+8801726238234"
}

.Net Code Example:

var client = new RestClient("https://ap15.salesforce.com/services/data/v42.0/sobjects/Contact");


var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "4c682644-7522-a855-1ee1-d5299d48a8e1");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer 00D2v000000Qgog!
AQgAQNyZpx_ibpW1QN1o6ogcxNSFTTcwNhRGdtSM4Q4UbvKusv_497hgCE58cRopLtHRDrLcp0O
DweU6d6MTqqpIfbU2EsH1");
request.AddParameter("application/json", "{\n \"LastName\" : \"Logistics and
Transport\",\n \"Phone\" : \"+8801726238234\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Response: New Contact will be created :


Response JSON:
{
"id": "0032v00002oIsfmAAC",
"success": true,
"errors": []
}

You can check this record by get request as above


With end point
"id": "0032v00002oIsfmAAC",

https://ap15.salesforce.com/services/data/v42.0/sobjects/Contact/0032v00002oIsfmAAC

You might also like