HttpResponseException: Bad Request occurs while implementing call inbound using vonage SDK

Viewed 224

I am trying to implement call functionality using nexmo api in my spring MVC project, but I keep on getting the below exception

com.vonage.client.VonageResponseParseException: Unable to parse response.
        at com.vonage.client.AbstractMethod.execute(AbstractMethod.java:105) ~[client-6.1.0.jar:6.1.0]
        at com.vonage.client.voice.CallsEndpoint.post(CallsEndpoint.java:57) ~[client-6.1.0.jar:6.1.0]
        at com.vonage.client.voice.VoiceClient.createCall(VoiceClient.java:61) ~[client-6.1.0.jar:6.1.0]
.............................
Caused by: org.apache.http.client.HttpResponseException: Bad Request
        at org.apache.http.impl.client.AbstractResponseHandler.handleResponse(AbstractResponseHandler.java:69) ~[httpclient-4.5.1.jar:4.5.1]
        at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:65) ~[httpclient-4.5.1.jar:4.5.1]
        at com.vonage.client.voice.CreateCallMethod.parseResponse(CreateCallMethod.java:57) ~[client-6.1.0.jar:6.1.0]
        at com.vonage.client.voice.CreateCallMethod.parseResponse(CreateCallMethod.java:32) ~[client-6.1.0.jar:6.1.0]
        at com.vonage.client.AbstractMethod.execute(AbstractMethod.java:102) ~[client-6.1.0.jar:6.1.0]
        ... 51 more

Below is my code logic

VonageClient client = VonageClient.builder().applicationId(APPLICATION_ID).privateKeyContents(PRIVATE_KEY).build();
Ncco ncco = new Ncco(TalkAction.builder("message").build());
Call call = new Call(TO_NUMBER, FROM_NUMBER, ncco);
CallEvent result = client.getVoiceClient().createCall(call);

Although inbound calls work using curl command below

curl -X POST https://api.nexmo.com/v1/calls\
  -H "Authorization: Bearer "$JWT\
  -H "Content-Type: application/json"\
  -d '{"to":[{"type": "phone","number": "TO_NUMBER"}],
      "from": {"type": "phone","number": "FROM_NUMBER"},
      "ncco": [
        {
          "action": "talk",
          "text": "This is a text to speech call from Vonage"
        }
      ]}'
1 Answers

The code provided here appears to work fine on the 5.6.0 version of the nexmo client - I would make sure you're all the way up to date.

That error is suggesting that the content being passed to the nexmo API is bad so it's probably worth turning on some logging if this continues to be a problem after upgrading here's an example of how to turn on logging. this will allow you to see exactly what it's passing along and perhaps find out what the issue is.

Related