News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
How to handle validation token for webhook subscription in apex.
Tags: rest api
Oct 27, 2020 at 6:22am   •   0 replies  •  0 likes
Aabid Khan

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.



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us