forcetk in VisualForce Page - it works fine (below is the code).

forcetkClient = new forcetk.Client();
forcetkClient.apexrest('/rest-api/get', function (data, status, xhr) {
                data = JSON.parse(data);
                // ...
            }, function (xhr, textStatus) {
                console.log(xhr, "Request failed: ", textStatus);
            }, 'GET', params);

Now I'm trying to do the same in lightning:container html page ... but I'm not sure how to get the Api.Session_ID - and then I found this: getRESTAPISessionKey (link - https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/container_npm_getrestapisessionkey.htm).

The above code works fine in VF page, but the same in lightning:container (with getRESTAPISessionKey) is giving the below error:

HTTP ERROR 400 Problem accessing /services/proxy. Reason:

Unable to forward request due to: Stream closed

Any suggestions/corrections to make it work in the lightning:container??


2 Answers 2



API access in lightning:container apps is revoked. Apps can still access org data through Apex remoting calls.


On a Visualforce page, using Lightning Components for Visualforce, you can obtain the current Visualforce session ID using the expression {! $Api.Session_ID }. This session is intended for use only on Visualforce pages.

Elsewhere, an authenticated session is obtained using OAuth, following the same process you’d use to obtain an authenticated session to use with the REST API. In this case, you obtain an OAuth token, and can use it anywhere.

SRC: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/lightning_out_authentication.htm?search_text=session

The session id you pass is only valid for VF page you opened. Now when you try to use that same session ID for REST API calls using Force.TK it wont work as that session is not recognized and hence the error.

Force.TK was supposed to used with VF and not lightning and hence is considered as ancient, probably this is the time to decide to ditch VF and move to Lightning components.

That being said.. You can still make force.tk work by getting OAUTH2 flows to get SESSIONID or AccesToken which will be valid for force.tk rest API calls.

Oauth flows link : https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_authentication.htm

Can getRESTAPISessionKey be used, well theoretically its as good as building on frontend. Salesforce in SPRING 18 has blocked API access from lightning:contai er thus it might not be useful. Src: https://releasenotes.docs.salesforce.com/en-us/spring18/release-notes/rn_lc_api_revert_cruc.htm


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .