diff --git a/forcetk.js b/forcetk.js index f754db9..a2ce975 100644 --- a/forcetk.js +++ b/forcetk.js @@ -249,8 +249,10 @@ if (forcetk.Client === undefined) { * @param [error=null] function to which jqXHR will be passed in case of error * @param [method="GET"] HTTP method for call * @param [payload=null] payload for POST/PATCH etc + * @param [paramMap={}] parameters to send as header values for POST/PATCH etc + * @param [retry] specifies whether to retry on error */ - forcetk.Client.prototype.apexrest = function(path, callback, error, method, payload, retry) { + forcetk.Client.prototype.apexrest = function(path, callback, error, method, payload, paramMap, retry) { var that = this; var url = this.instanceUrl + '/services/apexrest' + path; @@ -268,7 +270,7 @@ if (forcetk.Client === undefined) { that.refreshAccessToken(function(oauthResponse) { that.setSessionToken(oauthResponse.access_token, null, oauthResponse.instance_url); - that.ajax(path, callback, error, method, payload, true); + that.apexrest(path, callback, error, method, payload, paramMap, true); }, error); } else { @@ -280,6 +282,13 @@ if (forcetk.Client === undefined) { if (that.proxyUrl !== null) { xhr.setRequestHeader('SalesforceProxy-Endpoint', url); } + //Add any custom headers + if (paramMap === null) { + paramMap = {}; + } + for (paramName in paramMap) { + xhr.setRequestHeader(paramName, paramMap[paramName]); + } xhr.setRequestHeader(that.authzHeader, "OAuth " + that.sessionId); xhr.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + that.apiVersion); }