I have created Named Credential for a SharePoint Site successfully. I am trying to call the Named Credential with path specified through Apex. I am having trouble in specifying the path name. For example the path is /_api/web/lists/getbytitle('Salesforce Test List')/items?$select=ID,Title. How do I specify that in the below code?

Http http = new Http();
HttpRequest req = new HttpRequest();
req.setHeader('Content-Length', '512');
req.setHeader('Accept', 'application/json; odata=verbose');
req.setEndpoint('callout:SPO_Integration/_api/web/lists/getbytitle('Salesforce Test List')/items?$select=ID,Title');
HttpResponse response = http.send(req);

As per Salesforce documentation, The named credential should be URL or root URL of the callout endpoint. Must begin with http:// or https://. Can include a path but not a query string. Examples:

You can, however, append a query string and a specific path in the callout definition’s reference to the named credential. For example, an Apex callout could reference the named credential “My_Payroll_System” as follows.

HttpRequest req = new HttpRequest();

In your case named credential should be like this.


And in apex you can pass the parameters as below.


I was able to call the Named Credential by sepcifying the path name.

Named Credential: https://yourdomain.sharepoint.com/sites/testsfint

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.