D7 Verify

ÜCRETSİZ
Verified
Taraf Direct7 Networks | Güncelleyen 7일 전 | SMS
Popülerlik

9.5 / 10

Gecikme

421ms

Hizmet Düzeyi

100%

Tüm Tartışmalara Dön

Need help to set HTTP Header

avatar
yaram1310
2년 전

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());
}

avatar
d7admin commented 2년 전

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

avatar
d7admin commented 2년 전

Dear Customer,

Please share your latest code to support@d7networks.com and our development team will have a look in to it asap.

avatar
yaram1310 commented 2년 전

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’);

avatar
d7admin commented 2년 전

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.

Aşağıya yorum ekleyerek tartışmaya katılın:

Yeni yorumlar göndermek için giriş yapın / kaydolun
Değerlendirme: 5 - Oy Sayısı: 2