cancel
Showing results for 
Search instead for 
Did you mean: 

How to consume saleforce Apex Rest API service using OAuth 2.0 in HANA XS

Former Member
0 Kudos

SalesforceAPI.xshttpdest

description = "My HTTP destination";
host = "dbsystemsp2000350343trial.hanatrial.ondemand.com";
port = 443;
pathPrefix = "/services/apexrest/AccountDetails";
proxyType = http;
proxyHost = "salesforcecors.herokuapp.com";
proxyPort = 4300;
authType = none;
useSSL = true;
timeout = 30000;
oAuthAppConfigPackage = "SalesforceAPI";
oAuthAppConfig = "SalesforceAPI";
sslHostCheck = true;
sslAuth = client;

SalesforceAPI.xsoauthappconfig

{
	"clientConfig":"SalesforceAPI:SalesforceAPI",
	"description": "Salesforce test application for OAuth"
}

SalesforceAPI.xsoauthclientconfig

{
"clientFlavor":"SalesforceAPI:SalesforceAPI",
"clientID":"3MVG9E4..z.hDcPKzw7ZbEaOhlOjjkbWUV_7.dMV.su.Be_4Cmey0G5cvmOMuQlF6P.nO1FDLzOhx0aNh7014",
"clientAuthType":"cert",
"authorizationEndpointURL":"/services/oauth2/authorize",
"tokenEndpointURL":"/services/oauth2/token",
"revocationEndpointURL":"/services/oauth2/token/revoke",
"flow":"authCode",
"description":"OAuth Client for Salesforce",
"samlIssuer":"" ,
"redirectURL":"/services/oauth2/callback",
"scopeReq":"maxScopes",
"shared":"true",
"modifies":"SalesforceAPI:SalesforceAPI"
}

token.xsjs

function getData() {	
	// create client
	var client = new $.net.http.Client();


	// where and what to send
	var dest = $.net.http.readDestination("SalesforceAPI", "SalesforceAPI");
	var request = new $.net.http.Request($.net.http.GET,"/services/apexrest/AccountDetails"); // new Request(METHOD, PATH)
	
	// send the request and synchronously get the response
	client.request(request, dest);
	var response = client.getResponse();
	
	// get the body
	var body;
	if(!response.body){
	    body = "I am Here";
	}else{
		body = response.body.asString();		 
	}   	
	client.close();       

	// send the response as JSON
	$.response.contentType = "application/json";
	$.response.setBody(JSON.stringify({"status": response.status, "body": body}));
}










Accepted Solutions (0)

Answers (1)

Answers (1)

gregorw
Active Contributor

Please check the documentation Use XS Destinations for Internet Connectivity and correct your host, port, proxyHost and proxyPort parameters.