question

Aabid Khan avatar image
Aabid Khan asked ·

How to handle validation token for webhook subscription in apex.

To handle validation token, I'm creating below code.

@RestResource(urlMapping='/test/v1/')

global class ringcentralWebhook {

@HttpPost

global static String doPost() {

RestRequest req = RestContext.request;

RestResponse res = RestContext.response;

String JsonBody = req.requestBody.toString();

Map<String, Object> body = (Map<String, Object>)Json.deserializeUntyped(JsonBody);

String s = String.valueOf(body);

contact c = new contact(lastName = 'test ringcentral again', description=s);

insert c;

Map<String,Object> m = (Map<String,Object>)req.headers;

String vt1 = String.valueOf(m.get('Validation-token'));

String header = 'Validation-Token';

res.addHeader(header, vt1);

res.statusCode = 200;

return String.valueOf(res);

}

}


for callout from postman: -

In Header : -

Accept application/json

Authorization Bearer myToken

Content-Type application/json

For body (raw): -

{

"eventFilters": [

"/restapi/v1.0/account/~/extension/~/message-store?type=SMS&direction=Inbound"

],

"deliveryMode": {

"transportType": "WebHook",

"address": "https://aabidlwc-developer-edition.ap16.force.com/services/apexrest/test/v1/";

},

"expiresIn":100

}


It through error : - "errorCode": "SUB-522", "message": "WebHook responds with incorrect HTTP status. HTTP status is 500", "status": "500"

If I'm wrong in any place please correct me.

webhookapex
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.