I am using the below code to generate HTTP request . I am getting unAuthorized when called from Salesforce. Can you help me.
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(‘https://d7networks.com/api/verifier/send’);
request.setMethod(‘POST’);
//request.addHeader(‘Content-Type’, ‘application/json;charset=UTF-8’);
request.setHeader(‘Authorization’,‘bb353590b3ef57a3a8514d4e8edf943a30d70e6b’);
request.settimeout(2500);
// Set the body as a JSON object
request.setBody(’{“mobile”:"+15127109616"},{“sender_id”:“D7VERIFY”},{“message”:“Your otp code is {code}”},{“expiry”:“900”}’);
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ’ +
response.getStatusCode() + ’ ’ + response.getStatus());
} else {
System.debug(response.getBody());
}
加入讨论 - 在下面添加评论:
Also could you please try the following code and share us the result:
// create a json string body to send
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField(‘mobile’, ‘+15127109616’);
gen.writeStringField(‘sender_id’,‘D7VERIFY’);
gen.writeStringField(‘message’,‘Your otp code is {code}’);
gen.writeStringField(‘expiry’,“900”);
gen.writeEndObject();
String jsonS = gen.getAsString();
System.debug(‘jsonMaterials’+jsonS);
HttpRequest request = new HttpRequest();
request.setHeader (‘Authorization’,‘Token bb353590b3ef57a3a8514d4e8edf943a30d70e6b’);
request.setEndpoint(‘https://d7networks.com/api/verifier/send’);
request.setMethod(‘POST’);
request.setbody(jsonS);
Http http = new Http();
HTTPResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode ()!= 201) {
System.debug (‘The status code returned was not expected:’ +
response.getStatusCode () +’’ + response.getStatus ());
} else {
System.debug (response.getBody ());
}
Ref:https://developer.salesforce.com/forums/?id=9060G000000BgMfQAK
Dear Customer,
Please share your latest code to support@d7networks.com and our development team will have a look in to it asap.
i have tried both these , still they are not working i am getting bad request
request.setHeader(‘Authorization’,‘token bb353590b3ef57a3a8514d4e8edf943a30d70e6b’);
and
request.setHeader(‘Authorization :’,‘token bb353590b3ef57a3a8514d4e8edf943a30d70e6b’);
Dear Customer,
Please use string “Token” infront of the API key in Authorization section. So the auth header should be :
authorization: ‘Token bb353590***’,
Please note that the discussions on RapidAPI is publicly visible and accessible to others. So it will be good to regenerate the token before you go live with the setup.
you can contact support@d7networks.com from your registered email to regenerate the token.