Issue while passing content as a body to azure function in adf.

Amar Agnihotri 891 Reputation points
2022-07-12T06:53:44.523+00:00

Hi,
I have created an azure function which is getting an input string and converting it to the valid Json format. The function is working fine in azure portal and in postman. This is the format of input string that it is taking
219801-image.png

and i
this is the format of output string in which it is converting -

219792-image.png

This is working fine in azure portal where input string is being passed as -
219736-image.png

And creating a valid output
219716-image.png

Now in adf the input to the function is coming from the variable from the previous activity -

219755-image.png

This is the data the variable is holding
( Name of variable is Data2 and this is of string type )-
219764-image.png

Now i passed this data2 variable value as input to azure function activity as
219776-image.png

When pipeline runs it throws an error -
219756-image.png

I found in the output that the input is being passed to azure function in some disturbed format -
219758-image.png

but for function to work . The input to the function should be like -
219783-image.png
So i believe that there is something missing in passing the content as body to azure function . Please suggest something to get this resolved.

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

3 answers

Sort by: Most helpful
  1. Amar Agnihotri 891 Reputation points
    2022-07-21T08:20:05.08+00:00

    @MartinJaffer-MSFT

    Hi, The issue has been resolved . Actually, in adf azure function activity the content inside the body is passed as a text to the azure function . Adf doesn't pass the content as a json and since i had defined in the azure function definition to read body content as a json object so that's why it was not picking up the input but when i was trying the same input in the azure function app then it was working fine. I changed the code in function definition to read the content body as a string rather than as a json object then it started working fine. Also, i want to tell you that i tried using @json (variables('data2')) also but that was also not working

    Thanks for your support

    2 people found this answer helpful.

  2. MartinJaffer-MSFT 25,991 Reputation points
    2022-07-13T17:40:34.683+00:00

    Hello @Amar Agnihotri ,
    Thanks for the question and using MS Q&A platform.

    As I understand you are trying to use Azure Functions to do some transformation from Data Factory. You are not getting the body you expected.

    You showed your body was

    {  
        "body":"{@variables('data2')}"  
    }  
    

    specifying "body" within the body is excessive. The contenst of the entire textbox are the body. you only need to do:

    @{variables('data2')}  
    

    220522-image.png

    Please do let me if you have any queries.

    Thanks
    Martin


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
      • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

  3. Amar Agnihotri 891 Reputation points
    2022-07-14T07:06:41.967+00:00

    @MartinJaffer-MSFT

    here is the full code of function in txt file

    220569-jsonfunct.txt