Cron timer triggered Azure Function fetching async ajax data in XML to CosmosDB

Hi there,

Here’s how to setup a simple Timer Triggered Azure Function which, based on a scheduled cron setting, fetches a data-feed from a specified URL over https, and then stores it as a document into a pre-setup Azure CosmosDB that I won’t go into details with in this post.

First setup a Function App as described here:

Then add your function code logic, as for example (simplified but functional):

var https = require('https');
module.exports = function (context, myTimer) {
    https.get("", (res) => {
        var responseData = "";
        res.on("data", (chunk) => {
            responseData += chunk;
        res.on("end", () => {
            context.log("Request succeeded");
            context.bindings.outputDoc = responseData;
            context.res = {
                "status": 200,
                "body": responseData
    }).on("error", (error) => {
        context.log("Request failed.");
        context.res = {
            "status": 500,
            "body": error
    setTimeout(function () { 
        context.log("Timed out, request took too long.");
        }, 1000);

Make sure to specify the desired cron settings on the function Trigger input, and select a valid and prepared CosmosDB as an output.

You should now see the data document inside your CosmosDB on a regular scheduled basis 🙂 – Enjoy!