Call azure function from ADF

Obaid Ur Rehman 86 Reputation points
2022-06-22T18:05:11.033+00:00

Hi,

I have an azure function which takes three arguments i.e arg1, arg2, arg3 and does some processing. Gives error if the arguments are invalid or None. Here is how the code looks like:

def main(req: func.HttpRequest) -> func.HttpResponse:  
      
    arg1 = req.params.get('arg1')  
    arg2 = req.params.get('arg2')  
    arg3 = req.params.get('arg3')  
      
    if (not arg1) or (not arg3) or (not arg2):  
        return func.HttpResponse(  
             f"Please provide valid arguments. Args receive: arg1: \  
                 {arg1}, arg2: {arg2}, arg3 :{arg3} - Status:500",  
             status_code=500  
        )  
	  
	process(arg1,arg2,arg3)  

The azure function using activity is being called as follows:
214001-image.png

but it gives an error as follows:
214002-azferror.png

I have tried with Get method and providing arguments in headers. Can someone please help what could be the case? Could it be the way I am acessing these args in code the wrong way?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,294 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,593 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Obaid Ur Rehman 86 Reputation points
    2022-06-22T19:34:05.593+00:00

    Hi,

    It appears there was problem I was acessing the parameters inside azure function.

    There are two ways with post method:

    1. Send params via query and access them using req.params.get('arg1')
    2. Send params via body and access them using req_body = req.get_json() arg1= req_body.get('arg1')

    I have adopted 2nd approach now and it works fine.

    1 person found this answer helpful.