Home > Back-end >  ADF, CopyData & Rest API
ADF, CopyData & Rest API

Time:09-10

I actually try to make a simple pipeline to read JSON Data on a API REST and store it in a database.

I try first with a CopyData acticity. I set up the linked service, the dataset, etc etc...

I need to call an API with POST Method and a Body's payload. Everything is set, I launch the pipeline and... the api respond like i don't providethe Body's payload.

Double check it, check it via the generated json :

ADF: Body request - seems ok

and in the generated pipeline JSON

...
     "source": {
                        "type": "RestSource",
                        "httpRequestTimeout": "00:01:40",
                        "requestInterval": "00.00:00:00.010",
                        "requestMethod": "POST",
                        "requestBody": "{ \"startDate\":\"2022-09-01T00:00\", \"endDate\":\"2022-09-01T23:59\"}"
                    },
...

Because requestBody wait a string type, the double quote are escaped... Never wanted to work. Nothing to do. API never seems to find the body.

I find the "Web" activity and I decide to give it a quick try.

Same api call,same linked service, same dataset same url, same method, same body payload... Just a big copy&paste.

And it's work... So, why Web activity works and not CopyData?

I reopen the generated pipeline's JSON and :

Web Activity:

"body": {
   "startDate": "2022-09-01T00:00",
   "endDate": "2022-09-01T23:59"
},

Copy Activity:

"requestBody": "{ \"startDate\":\"2022-09-01T00:00\", \"endDate\":\"2022-09-01T23:59\"}"

Seems that Web activity don't request the body type to be a String. Maybe it's the problem, Maybe Copy rewrite body "badly" and it's fail.

So, Do I miss something? or Is it a bug?

And how do you do it? (consume API data in adf pipeline)

Cheers, Mike.

CodePudding user response:

You can use @json('{"startDate":"2022-09-01T00:00","endDate":"2022-09-01T23:59"}') in copy activity body

Ref1

After using the above dynamic content, my copy activity receives the requestBody as an object. Look at the following image:

enter image description here

CodePudding user response:

https://docs.microsoft.com/en-us/answers/questions/1000566/adf-copydata-amp-rest-api.html?childToView=1001129#answer-1001129

Just miss the additional header : content-type : application/json ... :)

  • Related