You need to sign in to do that
Don't have an account?
Michael M
Where to put authorization in HTTP Request
Hello, I am new to Integrations/ SOAP API, so apologize if this is an elementary question. I received documentation on how to fill the body of the http request, but I realize that I also need to add authorization into the request. I have the key and secret, but I don't know where to put that in the code.
1. Where would I put it in the request?
2. What would the key/value pair look like in the JSON?
Here is what my request looks like so far:
public Object makePostCallout() {
Lead ref =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id = :ApexPages.currentPage().getParameters().get('id')];
system.debug('***NAME OF REFERRAL***: '+ ref.firstname + ' ' + ref.lastname);
String ssnReplace;
if (ref.Patient_SSN__c != null){
ssnReplace = ref.Patient_SSN__c.replace('-','');
}
String genderLetter;
if (ref.Gender__c == 'Male'){
genderLetter = 'M';
} else if (ref.Gender__c == 'Female'){
genderLetter = 'F';
}
String first;
String second;
String third;
String d = String.valueOf(ref.Patient_DOB__c);
system.debug('***dob string raw: ' + d);
first = d.substring(0,4);
second = d.substring(5,7);
third = d.substring(8,10);
String dob = first + second + third;
system.debug('***dob formatted: ' + dob);
Map<string, string> patientInfoMap = new Map<string, string>();
patientInfoMap.put('social_security_number', ssnReplace);
patientInfoMap.put('birthdate', dob);
patientInfoMap.put('gender', genderLetter);
patientInfoMap.put('last_name', ref.lastname);
patientInfoMap.put('first_name', ref.firstname);
List<Object> patientInfoList = new List<Object>();
patientInfoList.add(patientInfoMap);
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('processing_mode', 'Realtime');
gen.writeStringField('request_type', '270');
gen.writeStringField('information_source_id', '1');
gen.writeStringField('submitter_system_id', '2');
gen.writeStringField('submitter_system_type', 'api');
gen.writeStringField('submitter_request_id', 'R1');
gen.writeStringField('submitter_user_id', '99');
gen.writeObjectField('subscribers', patientInfoList);
gen.writeEndObject();
String jsonS = gen.getAsString();
System.debug('***jsonMaterials***'+jsonS);
// Continuation con = new Continuation(40);
//con.continuationMethod='processResponse';
HttpRequest req = new HttpRequest();
req.setEndpoint('https://...(left out)');
req.setMethod('POST');
req.setBody(jsonS);
Http http = new Http();
// this.requestLabel = con.addHttpRequest(req);
HTTPResponse res = http.send(req);
// return con;
String result = null;
Integer statusCode = res.getStatusCode();
system.debug('***statusCode is***: ' + statusCode);
if(statusCode == 200){
system.debug('***API invoked successfully***');
result = res.getBody();
system.debug('***RESULT***: ' + result);
}
return result;
}
1. Where would I put it in the request?
2. What would the key/value pair look like in the JSON?
Here is what my request looks like so far:
public Object makePostCallout() {
Lead ref =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id = :ApexPages.currentPage().getParameters().get('id')];
system.debug('***NAME OF REFERRAL***: '+ ref.firstname + ' ' + ref.lastname);
String ssnReplace;
if (ref.Patient_SSN__c != null){
ssnReplace = ref.Patient_SSN__c.replace('-','');
}
String genderLetter;
if (ref.Gender__c == 'Male'){
genderLetter = 'M';
} else if (ref.Gender__c == 'Female'){
genderLetter = 'F';
}
String first;
String second;
String third;
String d = String.valueOf(ref.Patient_DOB__c);
system.debug('***dob string raw: ' + d);
first = d.substring(0,4);
second = d.substring(5,7);
third = d.substring(8,10);
String dob = first + second + third;
system.debug('***dob formatted: ' + dob);
Map<string, string> patientInfoMap = new Map<string, string>();
patientInfoMap.put('social_security_number', ssnReplace);
patientInfoMap.put('birthdate', dob);
patientInfoMap.put('gender', genderLetter);
patientInfoMap.put('last_name', ref.lastname);
patientInfoMap.put('first_name', ref.firstname);
List<Object> patientInfoList = new List<Object>();
patientInfoList.add(patientInfoMap);
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('processing_mode', 'Realtime');
gen.writeStringField('request_type', '270');
gen.writeStringField('information_source_id', '1');
gen.writeStringField('submitter_system_id', '2');
gen.writeStringField('submitter_system_type', 'api');
gen.writeStringField('submitter_request_id', 'R1');
gen.writeStringField('submitter_user_id', '99');
gen.writeObjectField('subscribers', patientInfoList);
gen.writeEndObject();
String jsonS = gen.getAsString();
System.debug('***jsonMaterials***'+jsonS);
// Continuation con = new Continuation(40);
//con.continuationMethod='processResponse';
HttpRequest req = new HttpRequest();
req.setEndpoint('https://...(left out)');
req.setMethod('POST');
req.setBody(jsonS);
Http http = new Http();
// this.requestLabel = con.addHttpRequest(req);
HTTPResponse res = http.send(req);
// return con;
String result = null;
Integer statusCode = res.getStatusCode();
system.debug('***statusCode is***: ' + statusCode);
if(statusCode == 200){
system.debug('***API invoked successfully***');
result = res.getBody();
system.debug('***RESULT***: ' + result);
}
return result;
}
I tried adding a Named Credential, but I do not see where to type in the key and secret from my integration documentation. I added a New Named Credential, and I had to create a Certificate to do so, so I created a Self-Signed Certificate, but nowhere did I see where I can type in the key and secret from the integration docs?