Skip to main content
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:

Header info in the PageReference not working!

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!

 
3 answers
  1. Mar 19, 2019, 7:19 AM
    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
0/9000