D7 Verify

無料
Verified
よって Direct7 Networks | 更新済み 2ヶ月前 | SMS
人気

9.5 / 10

レイテンシー

628ms

サービスレベル

100%

すべてのディスカッションに戻る

Need help to set HTTP Header

Rapid account: Yaram 1310
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());
}

Rapid account: D 7 Admin
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

Rapid account: D 7 Admin
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.

Rapid account: Yaram 1310
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’);

Rapid account: D 7 Admin
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.

ディスカッションに参加しましょう-以下にコメントを追加してください:

ログイン/サインアップして新しいコメントを投稿
評価:5-投票:2