Search code examples
c#smstwiliomessaging

Remove Messaging Webhook Programmatically from Twilio


Does anyone know of a way to remove a webhook in Twilio programmatically?

When I use the Update function in the Twilio library in C# and set the method, URL, and fallback URL to null, nothing changes in Twilio. I need to be able to remove the webhook from Twilio via my program.

Thanks in advance!

IncomingPhoneNumberResource.Update(pathSid: phoneSid, smsMethod: null,
    smsUrl: null,
    smsFallbackUrl: null
);

Solution

  • I finally found the answer to my question. In order to send back an empty URI for them to remove a webhook, you have to send back Twilio's EmptyUri.

    var uri = new Twilio.Types.EmptyUri();
    var phoneSid = "PNXXXXXXXXX";
    
    await IncomingPhoneNumberResource.UpdateAsync(
        pathSid: phoneSid,
        smsUrl: uri,
        smsFallbackUrl: uri
    );