How add Integer query param to a Rest Api Dynamically in Azure Data Factory Copy Activity

Sadafule, Ranjith Kumar 0 Reputation points
2024-07-29T16:10:11.6233333+00:00

Hi,
I have to make api calls to fetch data of multiple ids , The api accept the ids in the integer format .
I am using foreach and copy data activity to get the data from the Rest api, to dynamically include these integer ids how can I concatenate it to my main URL .

I need a solution to dynamically add my fixture ids to the URL to make those api calls .

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,623 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2024-07-30T07:31:39.53+00:00

    Define a parameter in your pipeline to store the base URL of your API.

    Then, create a dataset for your REST API. In the dataset URL, use a dynamic expression to include the integer query parameter.

    Use the ForEach activity to iterate over your list of integer IDs.

    Then, inside the ForEach activity, configure the Copy Data activity to use the dynamic URL with the integer query parameter.

    1. Define a Parameter for the Base URL: In your pipeline, define a parameter for the base URL, for example, BaseURL.
    2. Create a REST API Dataset: Create a REST API dataset with the URL field dynamically set. For instance:
      
         {
      
             "type": "HttpFile",
      
             "typeProperties": {
      
                 "url": {
      
                     "type": "Expression",
      
                     "value": "@concat(pipeline().parameters.BaseURL, '?id=', pipeline().parameters.id)"
      
                 },
      
                 "requestMethod": "GET"
      
             }
      
         }
      
      
    3. Set up the ForEach Activity: Add a ForEach activity to your pipeline. In the settings of the ForEach activity, pass the list of IDs that you want to iterate over. For example, if you have a list of IDs in an array parameter IDList, you can set it as the Items property of the ForEach activity.
    4. Add Parameters to the ForEach Activity: Add a parameter to the ForEach activity to pass the current ID to the Copy Data activity. For instance, you can name the parameter currentID.
    5. Configure the Copy Data Activity Inside the ForEach: Inside the ForEach activity, add a Copy Data activity. Set the source of the Copy Data activity to use the REST API dataset.
      • In the dataset properties, set the id parameter to the value of the current ID in the ForEach loop. Use dynamic content to achieve this.
      • In the Copy Data activity's source dataset, set the id parameter to @item(), which references the current item in the ForEach loop.

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.