Azure Data Factory复制活动与JSON数据

huangapple go评论49阅读模式
英文:

Azure Data Factory copy activity with json data

问题

我正在使用一个复制活动,请求方法为POST,从一个REST API复制JSON响应。该REST API需要一个包含日期和时间详细信息的主体,格式如下:

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

当我像上面示例中显示的那样将日期和时间硬编码时,它可以正常工作。但当我尝试将其设置为动态值,即将startdate设置为当前日期 - 1,将starttime设置为当前时间 - 24小时,将enddate设置为当前日期,将endtime设置为当前时间时,它就会失败。

简单来说,我想使API的主体动态化。

我尝试将enddate设置为"{@formatdatetime(utcnow(),'yyyy-MM-dd')}",将endtime设置为"{@formatdatetime(utcnow(),'hh-MM-ss')}",以及一些其他以上代码的组合,但都失败了。有人能帮我解决这个问题吗?

英文:

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.

答案1

得分: 0

  • 由于我没有像您那样的REST API访问权限,我已经使用“设置变量”活动来演示如何使用动态内容创建所需的主体。
  • 我使用了 addDays() 函数来从当前日期(1天)和当前时间(24小时,即1天)中减去1天。
  • 然后我使用 formatDateTime 以以下方式格式化了结果:
[ { "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')}" } ]
  • 结果如下所示:

Azure Data Factory复制活动与JSON数据

  • 结果如下所示:

Azure Data Factory复制活动与JSON数据

英文:
  • 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')}"} ]

Azure Data Factory复制活动与JSON数据

  • The result would be as shown below:

Azure Data Factory复制活动与JSON数据

答案2

得分: 0

你分享的JSON块本身不是JSON,我想知道在硬编码时它是如何工作的。

我看到你在使用@formatdatetime(utcnow(),'hh-MM-ss'),在我看来,你应该使用@formatdatetime(utcnow(),'hh-mm-ss')

** MM表示月份

** mm表示分钟

英文:

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

答案3

得分: 0

使用设置变量活动分别创建动态日期和时间,然后在复制活动的正文中使用该变量的输出。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月20日 00:14:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75501538.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定