Reputation: 3483
When giving the following configuration its returns always WebHook responds with incorrect HTTP status. HTTP status is 405.
This is the webhook configuration:
var token= access_token;
var _eventFilters = [];
_eventFilters.push('/restapi/v1.0/account/~/extension/' + 232102004 + '/presence?detailedTelephonyState=true&aggregated=true')
rcsdk.platform().post('/subscription',
{
eventFilters: _eventFilters,
deliveryMode: {
"transportType": "WebHook",
"encryption": false,
"address": "https://demo.example.com/backend/country-list/web_hook/?auth_token="+token
}
})
.then(function(subscriptionResponse) {
console.log('Subscription Response: ', subscriptionResponse.json());
})
.catch(function(e) {
console.error(e);
});
This is my Django webhook url:
@list_route(methods=['get'], url_path='web_hook')
def create_web_hooks(self, request, **kwargs):
query_params = request.query_params.dict()
from django.http import HttpResponse
response = HttpResponse()
if 'auth_token' in query_params:
response['Validation-Token'] = query_params['auth_token']
response['status'] = 200
response.write('Hello World')
return response
Thanks in advance
Upvotes: 0
Views: 334
Reputation: 16354
In your webhook response, the content of response['Validation-Token']
needs to be the value present in the RingCentral create webhook HTTP request's Validation-Token
header. The RingCentral OAuth 2.0 access token is not used in your webhook listener.
Your webhook example is in Python so here are some examples using both Django and Flask. You should check for the existence of the request header and, if present, set the value as the response header of the same name. The following shows how to set the header.
Django
In Django, request headers are available in HttpRequest.META
which renames headers using it's specific algorithm. META
is a dictionary so you can access the header in the following ways:
response['Validation-Token'] = request.META.get('HTTP_VALIDATION_TOKEN')
or
response['Validation-Token'] = request.META['HTTP_VALIDATION_TOKEN']
More information on Django handles this is available in the Request and response objects documentation for HttpRequest.META
:
https://docs.djangoproject.com/en/1.11/ref/request-response/#django.http.HttpRequest.META
This is the specific text on header renaming:
With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER.
Flask
Using Flask, you can access HTTP request headers using the flask.Request
dictionary-like object the following ways:
response['Validation-Token'] = request.headers.get('Validation-Token')
or
response['Validation-Token'] = request.headers['Validation-Token']
This is discussed in the Flask Incoming Request Data documentation:
http://flask.pocoo.org/docs/0.12/api/#incoming-request-data
Upvotes: 1