0

I have an EventGridTrigger Function which is invoked whenever an event is published to the event grid topic.

The default code for this function used to log the eventData without any issues.

I want to send this data to another HttpTrigger Function (say OutFunction2) and log it there. I can trigger the OutFunction2 from Postman, it works fine. However, when I try the same request using xhr2 from my eventGridTrigger function,

I get an error saying Error: The method or operation is not implemented.

I tried to add package.json and did npm install using Kudu Services

I still get the above error when I trigger the event from Test/Run Feature of Azure.

function.json file

{
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "eventGridEvent",
      "direction": "in"
    }  ]
}

index.js file


var XMLHttpRequest = require("xhr2");
var xhr = new XMLHttpRequest();
var url = "https://my-function-url"; //2nd function url (OutFucntion2)
module.exports = async function (context, eventGridEvent) {
xhr.open("POST", url);
xhr.setRequestHeader("Accept", "application/json,");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
   }};
var data = JSON.stringify(eventGridEvent.data);
xhr.send(data);
};

package.json file

{
  "name": "eventgrid",
  "version": "1.0.0",
  "description": "",
  "main": "./index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "date": "^2.0.1",
    "uuid": "^9.0.0",
    "xhr2": "^0.2.1",
    "npm": "^5.8.0"
  }
}

I may be missing something fundamental in function.json file, or in package.json.

I am not sure what is the correct format to provide an httpTrigger outbinding,

Kindly help me with a function.json code / rectification.

I am new to Azure functions and javascript, any help is appreciated.

Thanks in advance.

Mohammed Idris
  • 768
  • 2
  • 9
  • 26

1 Answers1

0
  • An alternative would be that Instead of xhr2 use axios where you can easily send the post request with the Json event grid data.

  • Just install axios using npm install axios and then add the following code before the export.module function.

var axios = require('axios');
  • Then use post function to call the http trigger and add Json string of the event grid trigger.
var data = JSON.stringify(eventGridEvent.data);

axios.post("<url of the http trigger function >",data).then(Response=>context.log(Response.body));
Mohit Ganorkar
  • 1,917
  • 2
  • 6
  • 11