Creating a Webhook Endpoint for Fetching DownloadURL based on Meeting ID

testp21
Tera Contributor

This is the sample payload-

 

{
   "id": "f659c***0fb2-42c8-95c7-45746d0d8741",
   "headers": {
       "uuid": "35***a3cc-451d-9be8-182fb8ea257f",
       "signature": +q4GmJiy+iK8sFOeGleBJTZtcFzDySIpJqIQuCFAL9rjMw7aqnwWgQBuZIPwQQ6RLPyHHfj2QoQkN****/2sCr3Bo+3MANIyjUgDLxnJRFVB7iiUo1AnSvS6880+VlIkHid2THFHw==",
       "webhook-id": "5710f**"
   },
   "payload": {
       "event": "recording.statusUpdate",
       "meeting": {
           "id": "bbbbb-4c***",
           "title": "Video Chat",
           "status": "LIVE",
           "endedAt": "2024-04-15T10:42:00.386Z",
           "roomName": "bbbbbe***",
           "createdAt": "2024-04-15T10:38:54.646Z",
           "sessionId": "a2485b79-60d0****",
           "startedAt": "2024-04-15T10:38:54.646Z",
           "organizedBy": {
               "id": "4d9**-b427-40a2-98bb-7609866d01aa",
               "name": "Test"
           }
       },
       "recording": {
           "id": "fff77b63-a129-4196*****",
           "status": "UPLOADED",
           "fileSize": 1034640,
           "roomUUID": "a2485b79-60d0-4996-ac3e-d1180ad815b0",
           "meetingId": "bbbb***-4",
           "stopReason": "{\"reason\":\"ALL_PEERS_LEFT\",\"caller\":{\"type\":\"INTERNAL\"}}",
           "downloadUrl": "https://-test.s3.ap-south-1.amazonaws.com/4d96470c-b427-40a2-98bb-76098/bbbbbe45-fee2-4c84-999e-d06f93d406b3_1713177566204.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA5YAHRKZROCSW65HS%2F20240415%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20240415T104258Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=c5b680f77f1e92df0c93ba6b5de807cb634c9c835a7d207c3b5bf8dc9aeb8bc6",
           "recordingId": "fff77b63-a129-4196-9751-18bd484ae891",
           "startedTime": "2024-04-15 10:39:27.993634Z",
           "stoppedTime": "2024-04-15 10:42:58.168425Z",
           "organizationId": "4d96470c-b427-40a2-98bb-7609866d01aa",
           "outputFileName": "bbbbbe45-fee2-4c84-999e-d06f93d406b3_1713177566204.mp4",
           "downloadUrlExpiry": "2024-04-22 10:42:58.365673Z",
           "recordingDuration": 208.189
       }
   },
   "timestamp": "2024-04-15T10:42:58.678Z",
   "statusCode": 200
}

 

Need to create a Webhook in ServiceNow to accept this payload and grep the download url from it and store the same in sericenow incident form.

please support. 

1 ACCEPTED SOLUTION

Amit Pandey
Kilo Sage

Hi @testp21 

 

You need to create a scripted REST API with following script-

 

(function process(request, response) {

    var payload = request.body.data;
    var meetingId = payload.meeting.id;

    gs.info('Raw Request Body =' + JSON.stringify(payload));

    var downloadUrl = payload.recording.downloadUrl;

    var incGr = new GlideRecord('incident');
    incGr.addQuery('u_meeting_id', meetingId);
    incGr.query();

    if (incGr.next()) {

        var incNumber = incGr.getValue('number');
        incGr.u_downloadurl = downloadUrl;
        incGr.update();


        gs.info('Updated u_video_recording_url for task ' + taskNumber + ' with meetingId: ' + meetingId);
        return "Meeting Recording URL updated successfully on the case task " + incNumber;
    } else {

        gs.error('No task found with meetingId: ' + meetingId);
        return "No matching record found";
    }
})(request, response);

 

Please mark my answer helpful and correct.

 

Regards,

Amit

View solution in original post

1 REPLY 1

Amit Pandey
Kilo Sage

Hi @testp21 

 

You need to create a scripted REST API with following script-

 

(function process(request, response) {

    var payload = request.body.data;
    var meetingId = payload.meeting.id;

    gs.info('Raw Request Body =' + JSON.stringify(payload));

    var downloadUrl = payload.recording.downloadUrl;

    var incGr = new GlideRecord('incident');
    incGr.addQuery('u_meeting_id', meetingId);
    incGr.query();

    if (incGr.next()) {

        var incNumber = incGr.getValue('number');
        incGr.u_downloadurl = downloadUrl;
        incGr.update();


        gs.info('Updated u_video_recording_url for task ' + taskNumber + ' with meetingId: ' + meetingId);
        return "Meeting Recording URL updated successfully on the case task " + incNumber;
    } else {

        gs.error('No task found with meetingId: ' + meetingId);
        return "No matching record found";
    }
})(request, response);

 

Please mark my answer helpful and correct.

 

Regards,

Amit