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.
In your application, change the base URL and route from
https://rest.nexmo.com/account/get-pricing/outbound/tohttps://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.
Find the API request in your current application. If you are using Node.js, your requests may look like the following:
Remove the
api_keyandapi_secretparameters, and replace them with anAuthenticationheader 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.
Note the change in data location in the response. The pricing and network information is now found in the
_embedded.countriesarray instead of thenetworksarray.Note the changes to key names. Key names now use
snake_caseinstead ofcamelCase. 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.
countryCodeis now located in the URL as thecountryquery parameter.countryNameis now located at_embedded.countries[X].country_name.countryDisplayNameis now located at_embedded.countries[X].country_name.currencyis now located at_embedded.countries[X].currency.defaultPriceis now located at_embedded.countries[X].price.dialingPrefixis now located at_embedded.countries[X].dialing_prefix.network[X].typeis no longer returned.network[X].priceis now located at_embedded.countries[X].price.network[X].currencyis now located at_embedded.countries[X].currency.network[X].mccis no longer returned.network[X].mncis no longer returned.network[X].networkCodeis no longer returned.network[X].networkNameis no longer returned.
- The response now more accurately reflects paging. You can compare the
pagekey with thetotal_pageskey to see if you are at the end of results, or check for the existence of the_links.nextkey. If you need to move to the next page, you can use the_links.next.hrefvalue to automatically determine and navigate to the next page.