This is a follow-up new question to This SE

Is it possible to create a custom REST API Class to allow an oAuth connected app client to download a dynamically generated PDF visualforce page via REST API? I've tried the above mentioned method and have only ever seen the result be an HTML page with javascript redirect to user login.

The user profile does have access to the PDF. My REST API Connection tests via Postman do show that I can pull standard REST API queries so my access_token is working. I'll note that the Rest API Visualforce scope documentation only allows access to public Sites. This is not a public VF page nor is it available via an anonymous sites page. So, is this just not possible?

I have the RestResource returning text/html for now to make it easier to debug in postman.

global without sharing class OnboardingPDF {
    global static void process() {

        String recordId = RestContext.request.requestUri.substringafterlast('/');
        system.debug('recordId: ' + recordId);

        PageReference pr = Page.OnboardingPlan;
        pr.getParameters().put('Id', recordId);

        RestContext.response.responseBody = pr.getContent();
        RestContext.response.headers.put('Content-Type', 'text/html');
        RestContext.response.headers.put('Content-Length', RestContext.response.responseBody.size()+'');

This is the path I'm using in postman with the oAuth access_token as an Authorize Bearer header.


And this is the path of the VF Page


1 Answer 1


There may be someone that can help figure out a way to get this to work in the manner you are attempting here, but in the meantime an alternative approach given your findings would be to host the rest resource on a force.com site, using encryption to secure it.

You must log in to answer this question.

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