Press enter to see results or esc to cancel.

The Basetrip: The Ultimate Traveling API

I’m always down to travel. Whether it’s eating mango sticky rice in Vietnam, swimming with sharks in Australia, or rock climbing in California, sign me up!

via GIPHY

That’s why I was so excited when I found the Basetrip API. There are a good amount of travel APIs out there, including a number of flight APIs. But the Basetrip API is the first I’ve found that provides local data specific to travelers (ex. electrical socket types).

Read on for…

  • An overview of the Basetrip API
  • A tutorial for a script that finds upcoming flights to a destination (via Google Flights API) and pairs that response with in-depth local travel information (via the Basetrip API)

The Basetrip API Overview

The Basetrip API accesses travel information for over 230 countries. The response includes helpful travel information like…

  • Tipping customs
  • Internet speeds
  • Currencies and credit card types accepted
  • Local alcohol laws

…and more. You can check out the Basetrip documentation here to learn more about what the API provides. A lot of the more intricate details can be unlocked by subscribing to a Pro, Ultra, or Mega plan. But don’t worry, the API is free when you subscribe to its Basic tier and make requests within the limit. You can find more details about the Basetrip pricing plans on RapidAPI.

Connecting to the Basetrip API

Now that you understand what kind of information you can access with the Basetrip API, let’s test some API calls.

Step 1: Create a RapidAPI account

In order to connect to the Basetrip API, you’ll first need to create a RapidAPI account. Head to the homepage and click “Login” to sign up for an account.  

 

Step 2: Subscribe to the Basetrip API

Once you have created an account, navigate to the Basetrip API pricing page to subscribe to a plan.  

Here, you will see four different pricing tiers. Each tier will unlock extra features and allow for a higher volume of requests to be made. For the scope of this tutorial, we only need to subscribe to the Basic Plan. This will allow us to test the API and build this API smash without spending money. Go ahead and click “Choose Plan” under the Basic tier. A modal should pop up asking for your credit card information.

Fill in your credit card information and click “checkout”. You will not be charged anything unless you exceed the maximum amount of monthly requests (in this case 1,000 requests).

 

Step 3: Make a test call

While you can call the API manually, a great way to test out an API is to use the RapidAPI tool within the browser. Navigate to the Basetrip API functions page. If you’re logged in, you should see that your X-Mashape-Key is already filled in — it’s generated when you initially create a RapidAPI account (RapidAPI and Mashape are part of one larger API marketplace). Testing the API is as easy as clicking TEST Function. You should see a JSON response on the right. Above the response, you can also export the API call in numerous different languages. Here is an example of the NodeJS code snippet:

In order to use this Unirest API call in a project, you must install the Unirest client. Simply follow the instructions on the Unirest website.

 

API Smash: Google Flights and the Basetrip API

Travel information is helpful, but let’s be real, flight prices can make or break a trip. We built a script for more effective adventure-planning. This project pairs Google Flights’ upcoming flights (and prices!) with the Basetrip API information for a more complete picture. Here’s how we did it.

Connecting to the Google Flights API

Now that we have fully connected to the Basetrip API, we must also connect to the Google Flights API. Connecting to the Google Flights API is a slightly different process. You do not need a subscription to connect to the API, but you do need to retrieve an API key from Google.

 

Step 1: Get a Google Flights API key

  1. Go to the Google Developers Console
  2. Log in with your google account or create a new account
  3. Select a project, or create a new one
  4. Go to the QRX Express Airfare API Dashboard on Google’s API Manager (Google acquired this API, so the name of the API isn’t “Google Flights API”)
  5. Click the “Enable” button towards the top of the page
  6. Go to the credentials tab on the left side of Google’s API manager to get your apiKey

 

Step 2: Make a test call

Using your shiny new apiKey, you can call the API at the Google Flights API functions page. Just pick an endpoint, then fill in the required parameters, including your apiKey.

Once you test out the API just like you did for the Basetrip API, you can again export the API call as a code snippet in the language of your choice. Check out our SDK docs to find out how to use/install RapidAPI for each language.

 

Combining both APIs to Implement the API Smash

Now that you’ve connected to both the Basetrip API and the Google Flight API within the browser, let’s combine them into one script that returns data from both about your destination!

The script we have created is written in Node, but you can use any language you prefer.

 

const RapidAPI = require('rapidapi-connect');

const rapid = new RapidAPI("****", "***************************");

const unirest = require('unirest');



// Get both destination arguments

let destinationFrom = process.argv[2];

let destinationTo = process.argv[3];



// Call Google Flights API first, passing two IATA city codes

rapid.call('GoogleFlightsAPI', 'searchSingleTrip', {

'apiKey': '*************************',

'origin': destinationFrom,

'destination': destinationTo,

'passengersAdultCount': '1',

'passengersChildCount': '0',

'fromDate': '2017-06-20'



}).on('success', (googleFlightsPayload) => {



// convert IATA destination city code to country code

 rapid.call('IATACodes', 'getCitiesByCodes', {

  'apiKey': '**********************',

  'cityCodes': `${destinationTo}`



 }).on('success', (destToCity) => {



// convert IATA country code to country name

 rapid.call('IATACodes', 'getCountriesByCodes', {

   'apiKey': '***********************',

   'countryCodes': `${destToCity[0].response[0].country_code}`



   }).on('success', (destToCountry) => {



// call the Basetrip API passing in the country name into the URL

     unirest.get(`https://thebasetrip.p.mashape.com/v2/countries/${destToCountry[0].response[0].name}`)

       .header("X-Mashape-Key", "*****************************")

         .header("Content-Type", "application/json")

           .header("Accept", "application/json")

             .end((result) => {



// Log the Basetrip and GoogleFlights data

               console.log(result.body, googleFlightsPayload);

             });

   }).on('error', (err) => {

      throw err;

   });

 }).on('error', (err) => {

  throw err;

 });

}).on('error', (err) => {

  throw err;

});

The script returns data from both the GoogleFlights API and the Basetrip API. To run the script, you must also include two arguments: the departure city and the destination city. Try running something similar to this in your terminal: ‘node [filePath] BOS PAR’ and see what kind of data you get back! Don’t forget, if you’re using the code from above, you need to add all the required API keys.

You’ll notice that I also included the IATACodes API in this script. Further proof that there is an API for everything! I found that the Google Flights API takes in IATA city codes as parameters, but the Basetrip API requires one to use full country names. Two calls to the IATA API will provide this conversion. Connecting to the IATACodes API is as easy as signing up here and using the API key generated for you.

Conclusion

Time to stop reading and start packing! Let us know what you think of the Basetrip API and feel free to clone the repo.

 

rapidlogoblue

Comments

10 Comments

heimarbeit

… [Trackback]

[…] Find More on|Find More|Find More Infos here|There you can find 76596 additional Infos|Informations on that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

daniel anton ripoff report

… [Trackback]

[…] Read More on|Read More|Find More Informations here|Here you will find 69141 additional Informations|Infos on that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

cosmetic dental in Boynton Beach FL

… [Trackback]

[…] Find More on|Find More|Find More Infos here|Here you will find 7624 additional Infos|Infos to that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

friv

… [Trackback]

[…] Read More here|Read More|Find More Informations here|Here you will find 5798 more Informations|Informations to that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

pezevenk

… [Trackback]

[…] Find More on|Find More|Find More Infos here|Here you can find 68867 additional Infos|Informations on that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

DMPK

… [Trackback]

[…] Read More on|Read More|Read More Infos here|Here you will find 21630 more Infos|Informations to that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

www.office.com/setup

… [Trackback]

[…] Read More on|Read More|Find More Infos here|There you can find 72698 more Infos|Infos on that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

Togel Online

… [Trackback]

[…] Find More here|Find More|Read More Infos here|There you can find 54735 additional Infos|Infos on that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

Sexo

… [Trackback]

[…] Read More here|Read More|Read More Informations here|There you can find 10557 more Informations|Infos to that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]

pervert

… [Trackback]

[…] Find More on|Find More|Find More Infos here|There you can find 17102 more Infos|Infos to that Topic: blog.rapidapi.com/2017/06/29/the-basetrip-the-ultimate-traveling-api/ […]


Leave a Comment

Tell us your thoughts!

Spread the API ❤️