Search code examples
node.jshttp-status-code-404twilioerror-codetwilio-twiml

Twilio: Hangup a call in an existing conference, ERROR 20404


Following situation:

  1. Someone called my Twilio Number
  2. Twilio requested my url
  3. Caller gets into a conference (don't starts until a second person join)
  4. TwiML makes call to a Mobile
  5. The Moblie dont accept the call

=> no second Person enters the conference so it wont stop and the caller is stuck there.

My solution is to end the whole call if this happens, I already know where to place the endCall function so this is not my problem. The function looks like this (You'll find it in the twilio API too):

client.calls(accountSid).update({
    status: "completed"
}, function(err, call) {
    if(err){
        console.log(err);
    }
});

My programm logic is fine, I see that this function is called at the right place but I receive this Error:

{ status: 404,
  message: 'The requested resource /2010-04-01/Accounts/AC/Calls/AC.json was not found',
  code: 20404,
  moreInfo: 'https://www.twilio.com/docs/errors/20404' }

I already red whats at the moreInfo url but I disqualify the solutions there. Maybe you have an idea whats the problem with this.


Solution

  • Twilio developer evangelist here.

    You are almost all the way there. Your problem is that you are using your accountSid when trying to update the call's status.

    You need to get hold of the callSid of the original call. You will find the callSid in the parameters that you receive in the incoming webhook when the person calls your Twilio number.

    app.post('/calls', function(req, res, next) {
      var callSid = req.body.CallSid;
      // store callSid somewhere for use later
    
      // return TwiML to set up conference and dial your mobile number
    });
    

    You'll need to save that callSid and then use it at this point later when you want to hangup the call.

    client.calls(callSid).update({
        status: "completed"
    }, function(err, call) {
        if(err){
            console.log(err);
        }
    });
    

    Let me know if this helps at all.