I'm learning integrations and found out about named credentials. I want to set a named credential for my Apex method which performs a callout to my scratch org:
@AuraEnabled(cacheable=true)
public static List<Object> restCallout(){
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://ability-data-6444-dev-ed.cs102.my.salesforce.com/services/apexrest/Johnny');
req.setHeader('Authorization', 'Bearer abcdef123456}');
req.setMethod('GET');
HttpResponse res = h.send(req);
System.debug(res.getBody());
List<Object> objs = (List<Object>)JSON.deserializeUntyped(res.getBody());
System.debug(objs);
return objs;
}
Scratch org web service:
@RestResource(urlMapping='/Johnny')
global class WebServiceFactory {
@HttpGet
global static void getRecord() {
List<JSONFactory> JSONs = new List<JSONFactory>();
for(integer i = 0; i<15; i++){
JSONs.add(new JSONFactory(i, 'Jan' + i, 'Test' + i));
}
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(JSONs));
}
}
I am slightly confused about which Identity Type and Protocol to choose, so that I can avoid typing this line:
req.setHeader('Authorization', 'Bearer abcdef123456}');
Identity Type options:
- Anonymous
- Per user
- Named principal
Protocol options:
- OAuth 2.0
- Password Authentification
- AWS Signature Version 4
- JWT
- JWT Token Exchange
Could anyone give me a hint?