function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SadishSadish 

Header info in the PageReference not working!

Hey Everyone - I'm trying to pass header info the external API endpoint and using "PageReference" class. I see the documentation (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_System_PageReference_getHeaders.htm) but some reason the header is still not set properly. 

My expectation is the EndPoint URL should be executed without any error screen.

But I'm getting the below error message:
error screen

And here my codeset:
Apex Class: FileDownload
public with sharing class FileDownload {
	public Pagereference doAction() {
        Pagereference newPage = new pagereference('https://<<myDomain>>/api/v1/loanadjudicate/<<externalIdValue>>/file/download');
        newPage.getHeaders().put('Ocp-Apim-Subscription-Key', '<<mySubscriptionKey>>');
        newPage.getHeaders().put('Content-Type', 'text');
        newPage.getHeaders().put('Method', 'GET');
        newPage.setRedirect(false);
        return newPage;
    }
}
VF: DownloadPage
<apex:page controller="FileDownload" action="{!doAction}">

</apex:page>

Any help is appreciated!
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sadish,

Greetings to you!

Please refer to the below links which might help you further with the above issue.

https://stackoverflow.com/questions/51519687/api-management-url-is-giving-missing-subscription-key-issue

https://stackoverflow.com/questions/42467898/azure-issue-token-api-returning-access-denied-due-to-missing-subscription-key

https://pvandenheede.wordpress.com/2017/07/12/azure-api-management-subscription-key-invalid/

https://www.tech-findings.com/2018/09/access-denied-due-to-missing.html

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
SadishKSadishK
Hey Khan - Thanks for sharing the details, but my question is this Salesforce issue or API management on external system issue?

Regards,
Sadish
SadishKSadishK
Also do let me know if I'm using the right method on Salesforce to set the headers?