How to Migrate from Pricing API v1 to Pricing API v2

Overview

This guide explains how to migrate from the Pricing API v1 to the Pricing API v2. The new version of the Pricing API includes changes to authentication, routes, and response structures. This guide will document the changes you need to make to your application so that you can update your integration.

Migrating to the Pricing API v2 is important to take advantage of the improved consistency, security, and flexibility offered by the new API.

Before you start

Before you begin your migration, ensure:

  • You have your existing Vonage API Key and API Secret.
  • You have reviewed this documentation to understand the new features and capabilities.
  • You have a testing or development environment to test changes before deploying to production.

Note the URL Change

The Pricing API v2 uses a new base URL for the API compared to v1.

  1. In your application, change the base URL and route from https://rest.nexmo.com/account/get-pricing/outbound/ to https://api.nexmo.com/v2/account/pricing/

Select the Appropriate Product

The Pricing API v2 only supports sms-outbound and voice-outbound, compared to the Pricing API v1 which supported sms, sms-transit, and voice. You will need to make sure to call the appropriate product name as this will change. In most cases sms-transit and sms can be changed to sms-outbound, and voice can be changed to voice-outbound.

Migrate to Basic Header Authentication

The Pricing API v1 used query parameter authentication to validate your request, and the Pricing API v2 now utilizes Basic Authentication using the Authorization header.

  1. Find the API request in your current application. If you are using Node.js, your requests may look like the following:

  2. Remove the api_key and api_secret parameters, and replace them with an Authentication header that uses Basic authentication.

Change to Process the New Response Structure

The Pricing API v2 now utilizes a JSON-HAL response structure to make it more consistent with other Vonage APIs. This is a different API response structure than the more flat response structure from the Pricing API v1, but provides some additional benefits like better paging of results.

  1. Note the change in data location in the response. The pricing and network information is now found in the _embedded.countries array instead of the networks array.

  2. Note the changes to key names. Key names now use snake_case instead of camelCase. This conforms to Vonage's API standards and keeps it consistent with our other API responses. Some locations of the keys have changed as well.

  • countryCode is now located in the URL as the country query parameter.
  • countryName is now located at _embedded.countries[X].country_name.
  • countryDisplayName is now located at _embedded.countries[X].country_name.
  • currency is now located at _embedded.countries[X].currency.
  • defaultPrice is now located at _embedded.countries[X].price.
  • dialingPrefix is now located at _embedded.countries[X].dialing_prefix.
  • network[X].type is no longer returned.
  • network[X].price is now located at _embedded.countries[X].price.
  • network[X].currency is now located at _embedded.countries[X].currency.
  • network[X].mcc is no longer returned.
  • network[X].mnc is no longer returned.
  • network[X].networkCode is no longer returned.
  • network[X].networkName is no longer returned.
  1. The response now more accurately reflects paging. You can compare the page key with the total_pages key to see if you are at the end of results, or check for the existence of the _links.next key. If you need to move to the next page, you can use the _links.next.href value to automatically determine and navigate to the next page.

See also