How to make an API request inside of an Azure function that runs on a schedule using Node.js

What is the Azure Function

Azure Functions is a cloud service available on-demand that provides all the continually updated infrastructure and resources needed to run your applications. You focus on the pieces of code that matter most to you, and Functions handles the rest. Functions provides serverless compute for Azure.

What is a function trigger

A Function trigger is an event which is responsible for the execution of Azure functions.

How to create an Azure timer trigger function to call API request


You must have an Azure paid account to continue this tutorial

Create Function App

STEP 01: From the Azure portal search and select Function App and click create

Azure Function App (

STEP 02: On the Basic page, enter the following settings

Azure Function App settings
Basic page

STEP 03: On the Hosting, Networking, Monitoring and Tags pages, if you want to change the settings, change them or else keep them as it is

Hosting Page
Networking page
Monitoring page
Tags page

STEP 04: On the Review + Create page, review your settings and create the function

Review + Create page

STEP 05: After deployment succeeded, Go to resource to see your function app

Deployment completion notification
Function App dashboard

Create Timer Trigger function

STEP 01: In your function app, select Functions, and then select + Create

STEP 02: Select Timer trigger template from the template list and add the function name and the schedule

STEP 03: After creating the Timer trigger function, select Code+Test and add the following code to index.js and save

const httpMod = require(‘https’);module.exports = function (context, myTimer) { const options = {   host: ‘’,   path: ‘/v1/bpi/currentprice.json’,   method: ‘GET’,   port:443, }; const customReq = httpMod.request(options, res => {   context.log(`statusCode: ${res.statusCode}`) }) customReq.on(‘error’, (error) => {  context.log.error(error) })customReq.end();};

This is a sample code for making an API GET request to a publicly available endpoint, you can get an idea from the above code snippet.

STEP 04: To change the function running schedule, select the function.json from the drop-down and add the CRON expression and save it, or else select the Integration tab in the left-side panel and change the Trigger value.

function.json from drop-down

You can get an idea about the way of writing CRON expressions from here.

STEP 05: You can test the function using Test/Run button and you can see the logs from the logs tab

Logs tab





Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store