Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sohalloran
Forked from richardvanhook/SimpleProxyClient.page
Last active June 13, 2023 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sohalloran/4682355 to your computer and use it in GitHub Desktop.
Save sohalloran/4682355 to your computer and use it in GitHub Desktop.
<apex:page docType="html-5.0" sidebar="false" showHeader="false"
standardStylesheets="false" cache="true">
<html lang="en">
<head>
<meta charset="utf-8"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
var SESSION_ID = '{!$Api.Session_ID}';
var serverURL = '{!SUBSTITUTE(SUBSTITUTE(LEFT($Api.Partner_Server_URL_210, FIND( '/services', $Api.Partner_Server_URL_260)), 'visual.force', 'salesforce'), 'c.', '')}';
// If its a mydomain enabled org, the mydomain name needs to be stripped
var splitURL = serverURL.split(/\./g);
if(splitURL.length==4) {
splitURL[0] = 'https://';
serverURL = splitURL.join(".").replace('.','');
}
var PATH = 'services/data/v26.0/chatter/users/me';
$(function(){
$.ajax({
cache: false,
url: '/services/proxy',
beforeSend: function(xhr) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', serverURL + PATH);
xhr.setRequestHeader('Authorization', 'OAuth ' + SESSION_ID);
},
success: function(data,textStatus,jqXHR){
$('body').html('Done! You are <b>'
+ data.name
+ '</b>, and I, this humble page, retrieved your name from the REST API.');
}
});
});
</script>
</head>
<body>Loading...</body>
</html>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment