ringcentral / RingCentral.Net

RingCentral SDK for .NET
MIT License
19 stars 26 forks source link

Revoking Subscription via websockets extension fails #57

Closed beinnlora closed 6 months ago

beinnlora commented 1 year ago

When attempting to revoke an event Subscription via WebSocket extension, the Revoke() command is sent via Websocket but the Subscription is not revoked. A websocket message of type 'error' is returned:

***WebSocket outgoing message (07/09/2023 11:42:45): ***
[
  {
    "type": "ClientRequest",
    "messageId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "method": "DELETE",
    "path": "/restapi/v1.0/subscription/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  },
  null
]
******
***WebSocket incoming message (07/09/2023 11:42:45): ***
{
  "meta": {
    "type": "Error",
    "messageId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "status": 400,
    "headers": {
      "RCRequestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-xx"
    },
    "wsc": null
  },
  "body": {
    "errorCode": "WSG-808",
    "message": "Expected either '{' opening an object body or '\"' opening a string body but was another character"
  }
}

Note the null malformed object in the outgoing message, that is usually a "body":{}

Code snippet to reproduce:

var rc = new RestClient(config["clientId"], config["clientSecret"], config["server"]);
await rc.Authorize(config["jwt:appTest1_sandbox"]);
var wsExtension = new WebSocketExtension(new WebSocketOptions {debugMode = true});
await rc.InstallExtension(wsExtension);
var subscription = await wsExtension.Subscribe(filters, message => { Console.WriteLine("New Message: " + message); });
await subscription.Revoke(); //this produces the 

Relevant section of code: https://github.com/ringcentral/RingCentral.Net/blob/bc8f16566724447384e660653b2cc478ec1b2dd8/RingCentral.Net.WebSocket/Subscription.cs#L43-L51

Is it because the _wse.Request has no RequestBody but the WebSocket JSON outbound message constructor inserts string 'null' when RequestBody is null, instead of omitting the body object altogether?

The workaround is to use rc.Restapi().Subscription(id).Delete();

thankyou

tylerlong commented 6 months ago

Fixed: https://github.com/ringcentral/RingCentral.Net/commit/192b01a112a4701e414849bf01807d20010db86f