Download Vonage Voice API Recordings with Golang

Published May 18, 2020 by Lorna Mitchell

We love the Voice API and all the fun things you can do with it. Today I’m going to show you a Golang application I’m using to download the recordings of the calls.

When I make a call and record it, the API sends a webhook at the end of the call with all the information about the recording. My application receives this webhook and downloads the recording file itself.

Configure the Recording URL

When I add a record action to a Voice API NCCO, I can set the eventUrl to receive the recording notification. This incoming webhook arrives when the call is finished, and includes information about the recording and a link to download it.

My record action looks like this:

There are two things to notice here:

  1. This eventUrl is actually an array (it catches me out about one time in every three!)
  2. I’m using Ngrok to provide a publicly-available URL to my local development platform. You can read about Ngrok on the Developer Portal if you’d like to learn more about using this approach.

Receive the Webhook

The incoming webhook is JSON-formatted and looks something like this:

In my Golang code, I’m going to handle an incoming request to /recording and download the file, saving it to disk.

To authenticate, you will need a (JWT)[ which you can generate programmatically or from the command line. This example expects it to be in an environment variable JWT.

The entry point here is the main() function at the end of the code sample. It registers a /recording route and then starts a web server running on port 8080.

When I first run the code with go run main.go, not much happens! That’s because the web server is running and waiting for a request to arrive. When it does, if the route matches then it calls the downloadRecording() function and the interesting stuff starts!

This code first parses the incoming data; it is a POST request with a JSON body so I defined a struct that I could decode the data into. Once we have the URL, the program outputs it.

Download and Save the Recording

If things went well to this point then we can move on and add the steps to download the recording and save the file. When complete, the full downloadRecording() function looks like this:

Downloading recordings requires credentials, so this code shows how to add a JWT to the request before sending it.

Finally, the response to the download request is written to a local file. I used the recording ID as the file name since I know it will be unique; if it makes more sense to name with timestamps or something else then you could definitely do that in your own application.

Handling Recordings in your own Applications

Today’s example is basic but does show some key ingredients of working with Voice API; receiving webhooks in response to events and sending credentials to download the recordings. If you’re using something similar in your own applications or build on this example, let us know! We always enjoy hearing what you are all working on.

Leave a Reply

Your email address will not be published.

Get the latest posts from Nexmo’s next-generation communications blog delivered to your inbox.

By signing up to our communications blog, you accept our privacy policy , which sets out how we use your data and the rights you have in respect of your data. You can opt out of receiving our updates by clicking the unsubscribe link in the email or by emailing us at