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
subodh chaturvedi 17subodh chaturvedi 17 

i have a confusion In CURL in Rest API that how to make use of it During Authorization


Below is the Example provided to make the Authorization with the External system. But I am not sure how to make use of it in Authorization .
 
Passing your API key in an authorization header

The following example authenticates you with the page API. Along with the Page ID listed on the API page, we can fetch your page profile.
curl -H "Authorization: OAuth 89a229ce1a8dbcf9ff30430fbe35eb4c0426574bca932061892cefd2138aa4b1" \ https://api.statuspage.io/v1/pages/gytm4qzbx9t6.json

Passing your API key in a query param
curl "https://api.statuspage.io/v1/pages/gytm4qzbx9t6.json?api_key=89a229ce1a8dbcf9ff30430fbe35eb4c0426574bca932061892cefd2138aa4b1"

Security scheme type: API Key
header parameter name: Authorization
....................................................................................................................................................................................................................................
I am getting an Error :
Illegal string literal: Invalid string literal '\https://api.statuspage.io/v1/pages/gytm4qzbx9t6.json'. Illegal character sequence \h' in string literal.

Below is My code :
public list <contact> conlist= new list<contact>();
    
    public string PageID ='0ypqjmkwgqmh'; 
    
    Public statusPageCallout(list<contact>conlist){
        
        this.conlist = conlist;
        
        
    }
    
    public void execute(QueueableContext context)
    {
list<user> userlist = [SELECT id,name, User_Status_API_Key__c FROM User WHERE ID=:Userinfo.getUserId() limit 1];
        
        string API = userlist[0].User_Status_API_Key__c;
        system.debug('API------'+API);
        
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://api.statuspage.io/v1/pages/'+PageID);
        req.setMethod('POST');
        req.SetHeader('Authorization','curl -H "Authorization: OAuth'+API+'\https://api.statuspage.io/v1/pages/gytm4qzbx9t6.json');
        Http http = new Http();
        HTTPResponse res;
        try {
            res = http.send(req);
            System.debug(res.getBody());                
        } catch (Exception e) {
            System.debug('Callout Error:' + e.getMessage());
            
        }
        
}
SandhyaSandhya (Salesforce Developers) 
Hi,

Try to string concatenation as

String ex=OAuth+API+'\https://api.statuspage.io/v1/pages/gytm4qzbx9t6.json';

then use 

 req.SetHeader('Authorization','curl -H Authorization: ex)

Best Regards,
Sandhya
subodh chaturvedi 17subodh chaturvedi 17
Hi Sandhya,

Still, the Error Exist.

Below is the Example is given accordingly I have to set the Authorization.
The following example authenticates you with the page API. Along with the Page ID listed on the API page, we can fetch your page profile.
curl -H "Authorization: OAuth 89a229ce1a8dbcf9ff30430fbe35eb4c0426574bca932061892cefd2138aa4b1" \ https://api.statuspage.io/v1/pages/gytm4qzbx9t6.json

Passing your API key in a query param
curl "https://api.statuspage.io/v1/pages/gytm4qzbx9t6.json?api_key=89a229ce1a8dbcf9ff30430fbe35eb4c0426574bca932061892cefd2138aa4b1"

Security scheme type: API Key
header parameter name: Authorization

I have the Page id in My code & API key I am calling from Userinfo.