Home > database >  Why am I not be able to post json array from Azure Function activity at Azure Data Factory?
Why am I not be able to post json array from Azure Function activity at Azure Data Factory?

Time:01-30

I have created Azure Function activity on Azure Data Factory. The Azure Function activity calls a function of Azure Function App (Python, App Service Plan).

The Python code looks like as follows:

  # ...
  def get_request(self, req: func.HttpRequest):
    request_body_json = req.get_json()
  # ...

When I pass a json array as request body (like [{"key1": "value1"}, {"key2": "value2"}]) of the Azure Function activity, ValueError occurs.

However, when I pass the same json array to Web activity, the error does not occur. The Web activity calls the same Python code as Azure Function activity.

Why am I not be able to post json array from Azure Function activity at Azure Data Factory?

CodePudding user response:

I have reproduced in my environment and the below process worked for me: Firstly, I have reproduced in web activity and I have succeeded in my attempt with your code as below:

enter image description here

When I tried with Function Activity i have got the error.

Function Activity in adf do not pass the body as Json it passes as Text. so, we need to use an array variable for that.

So, I have set a variable as below:

enter image description here

After Set Variable, then I have created an azure function activity as below:

{

"rithwik":@{variables('emo')}

}

enter image description here

Then in function code:

import logging
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    request_body_json = req.get_json()
    return func.HttpResponse(f"Received the message: {request_body_json['rithwik']}", status_code=200)

request_body_json['rithwik'] as it will print the Value.

Output: enter image description here

Reference:

  • Related