Sipun
Sipun

Reputation: 5

Azure Data Factory copy activity with json data

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.

Upvotes: 0

Views: 360

Answers (3)

Sipun
Sipun

Reputation: 5

Used a set variable activity to create the dynamic date & time separately and then used the output of the variable in the body of copy activity.

Upvotes: 0

Himanshu Kumar Sinha
Himanshu Kumar Sinha

Reputation: 1806

The JSON block which you shared is not a JSON itself , I am wondering as to how this is working when you hardcoded .

I see that you are using @formatdatetime(utcnow(),'hh-MM-ss') to me it looks like you should use @formatdatetime(utcnow(),'hh-mm-ss'

** MM is for month

** mm is for minute

Upvotes: 0

Saideep Arikontham
Saideep Arikontham

Reputation: 6114

  • Since I don't have access to a REST API like yours, I have taken set variable activities to demonstrate how to create the required body using dynamic content.
  • I have used addDays() function to remove 1 day from both current date (1 day) and current time (24 hours and hence 1 day).
  • Then I have formatted the result using formatDateTime in the following way:
[ { "start_date": "@{formatDateTime(addDays(utcNow(),-1),'yyyy-MM-dd')}" "start_time": "@{formatDateTime(addDays(utcNow(),-1),'hh:mm:ss')}" "end_date": "@{formatDateTime(utcNow(),'yyyy-MM-dd')}" "end_date": "@{formatDateTime(utcNow(),'hh:mm:ss')}"} ]

enter image description here

  • The result would be as shown below:

enter image description here

Upvotes: 0

Related Questions