Introduction

The Open Movie Database (OMDb) API provides access to information about movies

Setting up the API in R

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(jsonlite)
## 
## Attaching package: 'jsonlite'
## 
## The following object is masked from 'package:purrr':
## 
##     flatten
library(magrittr)
## 
## Attaching package: 'magrittr'
## 
## The following object is masked from 'package:purrr':
## 
##     set_names
## 
## The following object is masked from 'package:tidyr':
## 
##     extract
library(httr)

Query parameters

t = movie title s = Search keyword i = IMDB ID type = “movie”, “series”, or “episode” y = year of release plot = “short” or “full”

Define the API endpoint and your key

omdb_endpoint <- “https://www.omdbapi.com/” api_key <- “apikey=cc7d9ef9” # PLEASE! Replace with your own API key

Example: Request information about Toy Story

title <- “&t=Toy Story” plot <- “&plot=short”

Build the complete API call URL

omdb_api_url <- paste0(omdb_endpoint, “?”, api_key, title, plot)

API example

omdb_api_url <- “https://www.omdbapi.com/?t=Toy%20Story&apikey=cc7d9ef9&plot=short” omdb_response <- GET(omdb_api_url) movie_data <- fromJSON(content(omdb_response, “text”)) write.csv(movie_data, “toy_story.csv”, row.names = FALSE)

Save as CSV

toy_story <- read.csv(“toy_story.csv”) toy_story