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.
@RestResource(urlMapping='/OnboardingPDF/*')
global without sharing class OnboardingPDF {
@HttpGet
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.
/services/apexrest/OnboardingPDF/a8F7500000009MB
And this is the path of the VF Page
/apex/OnboardingPlan?Id=a8F7500000009MB