CLI Challenges
Solve real-world problems and showcase your command-line skills by participating in our CLI challenges
A developer with a bit of Javascript experience should be able to write, run, and debug complex, multi-step jobs with OpenFn, using nothing but a text editor and their terminal.
If you are stuck and need help, please post in community.openfn.org.
Expand to see bug report template
Subject: Bug Report - [Brief Description]
**Description:** [Concise description of the bug.]
**Steps to Reproduce:**
1.
2.
3.
**Environment:**
- OS: [e.g., Windows 10]
- CLI: [e.g., v0.4.11]
- Node: [e.g., v 18.17.1]
- NPM: [e.g., 8.19.2]
**Attachments:** [Screenshots, error messages, or relevant files.]
🏆 Create personalized greeting
Overview:
Create a new hello.js
job to display a personalized greeting with your name.
Objective:
Compose a OpenFn job using common adaptor that outputs a greeting message containing your name.
Requirements:
Install the latest version of common adaptor.
openfn repo install @openfn/language-common
Tasks:
- Create a new file named
hello.js
. - Write a JavaScript script in
hello.js
to generate a greeting with your name. - Run the job using the command
openfn hello.js -a common -o tmp/output.json
. - Confirm the successful execution.
Review Checklist:
- Successfully created a new file
hello.js
. - Wrote a JavaScript script in
hello.js
for a personalized greeting. - Executed the job using the provided command.
- Verified the correct logs in the CLI output.
🏆 Fetch and inspect data via HTTP
Overview:
Write a job to fetch user data from the JSONPlaceholder API using OpenFn http adaptor.
Objective:
Fetch and print the details of the first user from the JSONPlaceholder API.
Requirements:
- Install the latest version of http adaptor.
openfn repo install @openfn/language-http
- Utilize the JSONPlaceholder API.
- Create a file named
getUsers.js
to contain the script.
Tasks:
- Create a file (
getUsers.js
) to house the script. - Fetch a list of users from the JSONPlaceholder API.
- Print the details of the first user.
- Run the job using OpenFn/cli:
openfn getUsers.js -a http -o tmp/output.json
. - Validate the expected CLI logs.
Review Checklist:
- Successful retrieval of user data.
- Correct printing of the first user's details.
- Proper use of the OpenFn http adaptor functions.
- Verified the correct logs in the CLI output.
🏆 Retrieve Covid-19 metadata
Overview:
Fetch and present COVID-19 metadata using The Atlantic's COVID Tracking Project API.
Objective:
Write a job that retrieves COVID-19 data from the API and calculate some aggregate values across a length of time of your chosing.
Requirements:
- Install the latest version of http adaptor.
openfn repo install @openfn/language-http
Tasks:
- Write an OpenFn operation to pull COVID-19 metadata from the
The Atlantic's COVID Tracking Project API.
- Utilize
https://api.covidtracking.com
as your baseUrl instate.configuration
.
- Utilize
- Run the job using the OpenFn CLI with the command
openfn your_operation_file.js -a http -o tmp/output.json
. - Evaluate the output and explore different ways to format or present the COVID-19 data by region.
Review Checklist:
- Successfully created an OpenFn operation file.
- Implemented code to retrieve COVID-19 metadata from the provided API.
- Executed the job using the provided CLI command.
- Explored various formatting or display options for the obtained data.
Feel free to experiment with the data presentation to enhance your understanding. Good luck! 🌐🦠
🏆 Extract names & emails
Overview:
In this challenge, you will use the JSONPlaceholder API to fetch comments for a specific post (post ID 1). Your task is to extract the "name" and "email" fields from each comment and log the extracted data.
Objective:
Write a job that retrieves comments for post ID 1, extracts the "name" and "email" fields from each comment, and logs the extracted data.
Requirements:
- Basic knowledge of JavaScript.
- OpenFn CLI installed on your machine.
Tasks:
Get Post Comments:
- Add an operation to fetch all comments for the post with ID 1 from the JSONPlaceholder API.
Extract Name and Email:
- Write a function to extract the "name" and "email" fields from each comment.
Log Extracted Data:
- Log the extracted data (name and email) from each comment to the console.
Review Checklist:
- Successfully fetched comments for post ID 1.
- Implemented a function to extract "name" and "email" from comments.
- Logged the extracted data to the console.
🏆 Control error messages
Debug what is causing an error on the following line of code and display the error message
// Get post where id is 180
get('posts/180');
🏆 Data transformation and cleaning
Overview:
In this challenge, you will use JavaScript global array methods, specifically
Array.reduce
, Array.filter
, or Array.map
, to create a series of operations
that fetch and filter posts by user ID.
Objective:
Write a job that retrieves posts by a specified user ID 1
Requirements:
- Utilize JSONPlaceholder API
https://jsonplaceholder.typicode.com
. - Install the latest version of http adaptor.
openfn repo install @openfn/language-http
Tasks:
Create File:
- Create a file named
getPosts.js
for your job.
- Create a file named
Get All Posts:
- Add the first operation to fetch all posts. Use the provided API or any other source of your choice that provides a list of posts.
Filter Posts by ID:
- Add a second operation with a function that filters posts by user ID. You
can use
Array.filter
or any other suitable method for this task.
- Add a second operation with a function that filters posts by user ID. You
can use
Fetch Posts for User ID 1:
- Use the function from the second operation to filter posts for user ID 1.
Review Checklist:
- Created
getPosts.js
file. - Successfully fetched all posts.
- Implemented a function to filter posts by user ID.
- Retrieved posts for user ID 1.