Explore APIs using the browser and the command line

To get intuition of how APIs work, we will explore two web-based APIs using the browser and the command line. We will explore Spotify and Twilio APIs using GET and POST methods.

Spotify: Search API (using GET)

  1. Click on Discover features. Check the features provided by spotify API.
  2. Select the Search feature, then click on read the docs. This API allows you to get Spotify Catalog information about albums, artists, playlists, tracks, shows or episodes that match a keyword string.
  3. The API endpoint is GET https://api.spotify.com/v1/search (shown in the right of the page).
  4. If you click on the API link above, you get an error message. This is because some parameters are required when calling an API.
  5. Inspect the Request and Response parts to understand how the API can be invoked and what response to expect.
  6. Let's try to invoke this API. Click on try in our web console at the end of this API documentation or by following this link: https://developer.spotify.com/console/get-search-item/?q=tania+bowra&type=artist
  7. The OAuth parameter is required which means that this API needs an authentication.


  8. Generate an access token by scrolling down and clicking on get token. Leave all boxes uncheckef and click request token. Follow the steps to sign in or sign up.


  9. Add keywords to your search by changing the parameter q.
  10. You can filter the results by type. Add comma separated types (valid types are: album , artist, playlist, track, show and episode)
  11. click on try it


  12. Inspect the answer returned in json format . The json object artists contains the array of items returned. Each item contains a collection of name/value pairs. For detailed information, check the Response section of the search for an item API .


  13. Let's explore some of the results. Visit the first link of the key spotify as shown below.


  14. This is the spotify home page of the first returned result. There are multiple items in the returned json response which means that the search query returned multiple artists for Tania Bowra
  15. You can invoke the API from a command line. Copy the curl command generated in your browser (on the right hand side). Notice that this is a GET method sent with parameters


Twilio API: Send SMS API (using POST)

Twilio is a comapny for developers that helps abstract away telephone communications. It lets you bring communications in your applications. It allows you to make and receive calls, and text messages, etc.

  1. Go to https://www.twilio.com/ and sign up for a free trial account.
  2. Verify your phone number and follow the registration steps as shown below.


  3. The first thing you need to do is to buy a free trial number. click on get a trial phone number, then choose this number.


  4. We will use the messaging API to send an sms. click on explore products and choose messaging.


  5. At the page bottom, read what you can do with a trial account.


  6. Click on start sending messages. Give a name to your first messaging service.


  7. click on Add senders. Select Phone number for sender type. Check your trial phone number, then Add phone numbers.


  8. Go back to Messaging. click on Try it out , then send an SMS.


  9. Let's test this API. Fill in from messaging service SID. Write your text in Body Text and click send test sms.


  10. Let's invoke this API from the command line. Check the generated curl command on the right. Click on Show Auth Token. If the authentication key is not added to the curl command, you have to add it manually. To do so, go to console, and click on your account. Under AUTH TOKEN, click on show to copy and add the key to the command.
    curl "https://api.twilio.com/2010-04-01/Accounts/your_account_sid/Messages.json" -X POST --data-urlencode "To=+33XXXXXX" --data-urlencode "Body=Hello again" --data-urlencode "MessagingServiceSid=messaging_service_id" -u your_account_sid:your_auth_token
  11. Replace your_account_sid, your_auth_token, messaging_service_id and +33xxxxxx with your actual values. To understand this curl command and how to invoke this API, check the API documentation at https://www.twilio.com/docs/sms/send-messages or by clicking on Docs and support from your dashboard. The API indicates that you need to make an HTTP POST to your account's Message resource. You need to create a message resource /2010-04-01/Accounts/{AccountSid}/Messages.json. You have to include the three parameters To, From (or messaging service sid), and Body, in addition to the authentication key
teaching_assistant/api/explore.txt · Last modified: 2021/09/22 10:46 by Nour
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0