Looking to connect Salesforce with Recosence, an external system. The scenario involves Recosense pushing data to Salesforce for storage. I have successfully created a post HTTP service and tested it in Postman, which generates an access token and records data in SFDC. But now the question is how to achieve the same using JavaScript.
Request for Access Token :
URL : https://test.salesforce.com/services/oauth2/token
Method: POST
Header :
Content-Type:application/x-www-form-urlencoded
Body :
grant_type:password
client_id:ConsumerKey
client_secret:SecretKey
username:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74d7e1e5f0ced1dfddfadddbdfddecd9cfd6db"><span class="__cf_email__" data-cfemail="692b4c40672040554d31425050424b4606660945504c4e">[email protected]</span></a>
password:Password+SecurityToken
Response :
{
"access_token": "00D5D0000008fEc!ARYAQO00kV_ijefERL8GaRWJnLPRxBkKDc39yPGpdiVzHdEP7Lb4dOTVBuUw7INSslGQjMdyYYDZjPREHfXwqZCEsi4YPFbp",
"instance_url": "-------------------------------------",
"id": "https://test.salesforce.com/id/00D5D0000008fEcUAI/0057F000000fpWFQAY",
"token_type": "Bearer",
"issued_at": "-----------------------",
"signature": "-------------------------------"
}
Request for Any API to Hit Salesforce(PUSH to SF):
URL: https://cs72.salesforce.com/services/data/v39.0/sobjects/Contact
Method: POST
Header :
Content-Type:application/json
Authorization:Bearer access_token(Fetched from request 1)
Body :
{"FirstName":"Test",
"LastName":"Vish",
"Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01637f797e34727f72747c51747f75767b717d273a767a78">[email protected]</a>"}
Response:
{
"id": "0035D000002zHrNQAU",
"success": true,
"errors": []
}
Attempting to replicate the functionality in JavaScript but encountering issues.