33  Where to find APIs

34 How to use APIs

See this video https://www.youtube.com/watch?v=8tilyqp4bZY

You can use the curl command line tool to get info from the APIs too.

Note that the following was compiled circa April 2024.

There is a incredible amount of data that can be accessed online by using an API. Some APIs are free to use but many will require some form of payment. Unfortunately, every API has its own set of rules and regulations. You must read the documentation for each API to understand what type of data is available through the API, how to use the API and how much it may cost.

In the past it was possible to go to “API Directory” website and “API Hubs” to find APIs. For example, see the following.

However, the API landscape has changed a lot in recent years. There are so many APIs, it has become almost impossible to maintain a list of available APIs. Many companies have an API that make their services available programatically via APIs. However, these services are hard to find if you don’t know what to look for. Many companies maintain a “developers” portion of their websites. You can also look for “API” in the fineprint of the website info.

34.1 Packages in R for specific APIs

Usually, accessing data from an API requires a technical understanding about how to use APIs in general. However, there are many R packages that make the process of accessing data from specific APIs much easier. These R packages “wrap” the technical details of how to access the API in R functions.

To get an idea of what APIs have R packages, you can search the list packages on CRAN (https://cran.r-project.org/web/packages/available_packages_by_name.html) for the word API.

# Find the number of packages that have the letters API in 
# the package name or in the description.
Loading required package: rvest
url = "https://cran.r-project.org/web/packages/available_packages_by_name.html"
page = read_html(url)
tables = html_elements(page, "table")
pkgs = as.data.frame(html_table(tables[[1]]))

names(pkgs) = c("package", "description")
rows = grepl("API", pkgs[,"package"], ignore.case = TRUE) | 
       grepl("API", pkgs[,"description"], ignore.case = TRUE)

numberOfApiPackages = sum(rows)

As of the date this document was compiled there were 566 packages on CRAN that have the letters API in either the name of the package or the description.

However, be aware that the API ecosystem can change rapidly and the R packages don’t always keep up. For example, twitter used to allow searching for tweets for free using their API. However, they started charging for those services. There are many youtube videos explaining how to search twitter for free using the twitter api via the “twittR” packager. These videos are no longer applicable.

34.1.1 R for finance

Below are some R resources for working with financial data Feb 2, 2024

R package for financial data - getting, charting, modeling

Related R package for doing technical analysis

34.2 APIs

You learn about many different APIs via this website https://rapidapi.com/collection/amazon-products