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