This question already has an answer here:
- Getting Session ID in Lightning 2 answers
When I make request tooling API from Apex by using lightning component, the error
This session is not valid for use with the REST API is responsed.
Also, the response status code is
401, and status is
How can we call tooling API without problem when we use lightning component.
By the way, when I use only "Debug - Open Excute Anonymous Window" in Apex, I can get correct and expected response.
Below is the code that I tried.
req = new HttpRequest(); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); req.setHeader('Content-Type', 'application/json'); req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v39.0/tooling/sobjects/GlobalValueSet/(Here is GlobalPickListId)?_HttpMethod=PATCH'); req.setMethod('GET'); httpreq = new Http(); res = httpreq.send(req); System.debug(res.getBody());
Thank you in advance.