How to add dynamic body in json POST method while using copy activity in ADF ?

Shaktipada Dash 0 Reputation points
2023-02-19T17:43:19.9266667+00:00

I am using a copy activity with request method as POST to copy the JSON response from a rest api. The rest api requires a body which contains date and time details in the below format

[ { "start_date": "2023-02-07" "start_time": "06:42:06" "end_date": "2023-02-07" "end_time": "08:47:06"

} ]

When am using the date and time as hardcoded values like the one shown above, it works fine. When I try to make it dynamic i.e. startdate as currentdate - 1 and start time as current time - 24hrs and end date as currentdate and end time as current time its failing. In simple words I want to make the body of the api as dynamic

I tried the end date as "{@formatdatetime(utcnow(),'yyyy-MM-dd')}" and end time as end time as "{@formatdatetime(utcnow(),'hh-MM-ss')}"

and few other combinations of the above code but its failing. Can someone please help me with this issue.

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
{count} votes

1 answer

Sort by: Most helpful
  1. KranthiPakala-MSFT 46,642 Reputation points Microsoft Employee Moderator
    2023-02-22T20:10:30.0233333+00:00

    Hi @Shaktipada Dash

    Welcome to Microsoft Q&A forum and thanks for reaching out here.

    Seems like you are pretty close to the solution. Have you tried the below format?

    To get the current date in the format yyyy-MM-dd :

    @{formatdatetime(utcnow(),'yyyy-MM-dd')}
    
    

    To get the current time in the format hh-MM-ss:

    @{formatdatetime(utcnow(),'hh-MM-ss')}
    

    Try configuring request body like below example:

    [ { "start_date": "@{formatdatetime(utcnow(),'yyyy-MM-dd')}" "start_time": "@{formatdatetime(utcnow(),'hh-MM-ss')}" "end_date": "@{formatdatetime(utcnow(),'yyyy-MM-dd')}" "end_date": "@{formatdatetime(utcnow(),'hh-MM-ss')}" } ]
    

    Please give a try and let me know how it goes. If that doesn't work, feel free to share the combinations you have tried so that it will help me try different ways other than what you have tried along with the error message you have received.

    Hope this helps. Let us know how it goes.


    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.