D7 Verify

무료
Verified
분류별 Direct7 Networks | 업데이트됨 2 months ago | SMS
인기

9.5 / 10

지연 시간

613ms

서비스 수준

100%

모든 토론으로 돌아가기

Need help to set HTTP Header

Rapid account: Yaram 1310
yaram1310
2 years ago

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

Rapid account: D 7 Admin
d7admin Commented 2 years ago

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

Rapid account: D 7 Admin
d7admin Commented 2 years ago

Dear Customer,

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

Rapid account: Yaram 1310
yaram1310 Commented 2 years ago

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

Rapid account: D 7 Admin
d7admin Commented 2 years ago

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.

아래에 의견을 추가하고 토론에 참여하세요.

새 댓글을 게시하려면 로그인 / 가입
등급: 5 - 투표: 2