From REST API to Snowflake: Building a Metadata-Driven Azure Data Factory Pipeline
Last updated: October 2026
Quick answer: Build a metadata-driven ADF pipeline by storing API configurations (URL, endpoint, target table) in a Snowflake metadata table. Use a Lookup activity to read configurations, a ForEach activity to iterate over each API, a Copy activity to fetch JSON responses into ADLS Gen2, and Script activities that create each VARIANT table and run COPY INTO from a Snowflake stage over the landing container. Connect to Snowflake with the Snowflake V2 connector and key-pair authentication. Add new APIs by inserting rows into the metadata table, with no pipeline changes needed.
Introduction
A metadata-driven Azure Data Factory pipeline automates REST API ingestion into Snowflake by decoupling pipeline logic from source configuration. If you are new to ADF, start with our beginner guide to creating a pipeline in Azure Data Factory. Instead of building separate ADF pipelines for each API, this approach reads API configurations from a Snowflake metadata table, dynamically fetches data, and loads it into Snowflake VARIANT columns.
This metadata-driven ADF pipeline tutorial demonstrates how to build a reusable pipeline that automatically fetches data from multiple REST APIs, stores JSON responses in ADLS Gen2, creates Snowflake tables dynamically, and supports incremental loads with comprehensive execution logging.
By the end of this tutorial, you will have a reusable, production-ready pipeline architecture that supports incremental loads through time-window parameters, comprehensive execution logging, and full error handling with success and failure tracking. For another Fabric-based approach, explore our Azure SQL to Snowflake via Fabric and OneLake pipeline.
Architecture Overview
The end-to-end data flow follows this path:
REST API → ADLS Gen2 (JSON Files) → Snowflake (VARIANT Table)
The pipeline executes the following steps in sequence:
- Read Metadata: API details (URL, endpoint, target table name) are stored in a Snowflake metadata table called
API_METADATA. - ADF Lookup Activity: Reads all active API configurations from the metadata table.
- ForEach Activity: Iterates over each API configuration returned by the Lookup.
- REST Copy Activity: Fetches the API response using the Azure Data Factory REST connector.
- Save to ADLS: Stores the raw JSON response as a file in Azure Data Lake Storage Gen2.
- Dynamic Table Creation: Uses a Script Activity to create the Snowflake target table if it does not already exist.
- Load into Snowflake: A Script Activity runs COPY INTO from a Snowflake stage over the same ADLS container, filling the VARIANT column and the source file name.
- Log Execution Status: Script Activities log success or failure into an execution log table.
- Time Window Control: For APIs that accept a time filter,
LAST_RUN_TSand theEND_TSpipeline parameter define the window each run requests.
Linked Services
The pipeline requires three linked services to connect ADF to external systems:
| Linked Service | Type | Purpose |
|---|---|---|
| REST Linked Service | REST | Connects to REST APIs using base URL and authentication settings. The base URL is parameterized so it can be dynamically set per API from the metadata table. |
| Snowflake Linked Service | Snowflake V2 | Connects with an account identifier, database, warehouse and optional role, and runs the Lookup and Script activities. Use KeyPair authentication with a TYPE = SERVICE user and keep the private key in Azure Key Vault, because the connector defaults to Basic (password) authentication and Snowflake's 2026 MFA rollout blocks passwords for service users. The V1 connector has been removed. |
| ADLS Gen2 Linked Service | Azure Data Lake Storage Gen2 | The landing area where the REST Copy Activity writes the JSON files. Snowflake reads the same container through its own stage and storage integration, so ADF never copies into Snowflake directly. |
Want this running in your own account? We build Snowflake platforms end to end: ingestion, modelling, access control, and the monitoring that tells you when a load drifts. Not slide decks. Not roadmaps. Real working systems you can point at.
Book a Snowflake call Snowflake consultingDatasets
Three datasets support the pipeline activities:
| Dataset | Format | Parameter | Purpose |
|---|---|---|---|
| JSON Dataset | JSON | FILENAME | Points to the ADLS location where JSON responses are saved, in a folder per API. The filename is built from the API name and the pipeline run ID, so each run writes a file the load step can name exactly. |
| REST Dataset | REST | BaseURL | Represents the REST API source. The BaseURL parameter is populated from the metadata table for each API. |
| Snowflake Source Dataset | Snowflake | None | Used by the Lookup activity to read from the API_METADATA table. |
Pipeline Design
Pipeline Parameter
The pipeline accepts one parameter:
- END_TS (String): Defines the end timestamp for the data extraction window. Together with
LAST_RUN_TSfrom the metadata table, it sets the time range requested from APIs that accept one.
Activity Flow
The pipeline is organized as follows:
1. Lookup Activity: Read API Metadata
The Lookup activity queries the API_METADATA table in Snowflake to retrieve all active API configurations. It uses a query like:
SELECT API_ID, API_NAME, BASE_URL, ENDPOINT, TABLE_NAME,
TO_VARCHAR(LAST_RUN_TS, 'YYYY-MM-DD"T"HH24:MI:SS') AS LAST_RUN_TS
FROM API_METADATA
WHERE IS_ACTIVE = TRUE;
The output is a list of API records that the ForEach activity will iterate over. The timestamp is converted to text in the query, because the Snowflake V2 connector returns TIMESTAMP columns as DateTimeOffset values, which are awkward to place in a URL.
2. ForEach Activity: Iterate Over Each API
The ForEach activity loops through each record returned by the Lookup. Inside the ForEach, the following activities are chained together:
2a. Script Activity (LOGSTART): Log Start of Execution
Before fetching any data, a Script Activity inserts a log record into the EXECUTION_LOG table with a status of RUNNING:
INSERT INTO EXECUTION_LOG (API_NAME, TABLE_NAME, STATUS, START_TIME)
VALUES (
'@{item().API_NAME}',
'@{item().TABLE_NAME}',
'RUNNING',
CURRENT_TIMESTAMP()
);
2b. Copy Activity (REST to JSON): Fetch API and Save to ADLS
This Copy Activity uses the REST dataset as the source and the JSON dataset as the sink. The source URL combines the BASE_URL and ENDPOINT fields from the metadata. For an API that accepts a time filter, the relative URL can carry the window, for example @concat(item().ENDPOINT, '?updated_since=', item().LAST_RUN_TS, '&until=', pipeline().parameters.END_TS); the parameter names depend on the API. The sink file name is @concat(item().API_NAME, '_', pipeline().RunId, '.json') in a folder named after the API, so each execution creates a unique file.
2c. Script Activity (TABLE CREATION): Create Snowflake Table Dynamically
A Script Activity executes a CREATE TABLE IF NOT EXISTS statement in Snowflake. The table stores the entire JSON response in a VARIANT column, with the load time and the source file name alongside it:
CREATE TABLE IF NOT EXISTS @{item().TABLE_NAME} (
RAW_DATA VARIANT,
LOAD_TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
SOURCE_FILE STRING
);
This eliminates the need to manually create tables before running the pipeline. Each new API added to the metadata table will automatically have its target table created on first execution.
2d. Script Activity (LOAD): Load the JSON File with COPY INTO
ADF's direct copy into Snowflake supports JSON only when the target table has a single VARIANT, OBJECT or ARRAY column, so a table with load metadata columns is loaded from Snowflake instead. A stage over the landing container is set up once:
CREATE STORAGE INTEGRATION adls_api_landing
TYPE = EXTERNAL_STAGE
STORAGE_PROVIDER = 'AZURE'
ENABLED = TRUE
AZURE_TENANT_ID = '<tenant-id>'
STORAGE_ALLOWED_LOCATIONS = ('azure://<account>.blob.core.windows.net/api-landing/');
CREATE STAGE API_LANDING_STAGE
URL = 'azure://<account>.blob.core.windows.net/api-landing/'
STORAGE_INTEGRATION = adls_api_landing
FILE_FORMAT = (TYPE = JSON);
The load step then copies exactly the file this run wrote, filling RAW_DATA and SOURCE_FILE, while LOAD_TIMESTAMP takes its default:
COPY INTO @{item().TABLE_NAME} (RAW_DATA, SOURCE_FILE)
FROM (
SELECT $1, METADATA$FILENAME
FROM @API_LANDING_STAGE/@{item().API_NAME}/
)
FILES = ('@{item().API_NAME}_@{pipeline().RunId}.json')
FILE_FORMAT = (TYPE = JSON);
2e. Script Activity (UPDATE LOG, SUCCESS)
On the success path of the load step, this Script Activity updates the execution log and moves the API's watermark forward. Running two statements in one Script Activity needs version 1.1 of the Snowflake V2 connector; on version 1.0, use two Script Activities:
UPDATE EXECUTION_LOG
SET STATUS = 'SUCCESS',
END_TIME = CURRENT_TIMESTAMP()
WHERE API_NAME = '@{item().API_NAME}'
AND STATUS = 'RUNNING';
UPDATE API_METADATA
SET LAST_RUN_TS = '@{pipeline().parameters.END_TS}'
WHERE API_NAME = '@{item().API_NAME}';
2f. Script Activities (UPDATE LOG, FAIL)
Each step that can fail gets its own failure logger. ADF treats several dependency lines into one activity as AND conditions, and when the REST copy fails, the steps after it are skipped, not failed, so a single logger wired to both On Failure paths would never run. A logger on each step's On Failure path records that step's own error. The expression doubles any apostrophe in the message, so the SQL string stays valid:
-- On Failure of Copy_REST_to_JSON. The logger for the load step has the same
-- shape and reads activity('Load_JSON_to_Snowflake').error.message instead.
UPDATE EXECUTION_LOG
SET STATUS = 'FAILED',
END_TIME = CURRENT_TIMESTAMP(),
ERROR_MESSAGE = '@{replace(activity('Copy_REST_to_JSON').error.message, '''', '''''')}'
WHERE API_NAME = '@{item().API_NAME}'
AND STATUS = 'RUNNING';
In this try-and-catch shape, ADF reports the pipeline as succeeded when the failure path succeeds. If failed APIs should show as failed runs in monitoring, add a Fail activity after each logger.
Metadata Table Structure
The API_METADATA table stores all configuration needed for each API source. Adding a new API requires only inserting a new row into this table:
CREATE TABLE API_METADATA (
API_ID INT,
API_NAME STRING,
BASE_URL STRING,
ENDPOINT STRING,
TABLE_NAME STRING,
IS_ACTIVE BOOLEAN,
LAST_RUN_TS TIMESTAMP
);
| Column | Description |
|---|---|
API_ID |
Unique identifier for the API source |
API_NAME |
Descriptive name of the API (e.g., "WeatherAPI", "ExchangeRates") |
BASE_URL |
The root URL of the API (e.g., "https://api.example.com") |
ENDPOINT |
The specific API endpoint path (e.g., "/v1/data") |
TABLE_NAME |
Snowflake target table name where data will be loaded |
IS_ACTIVE |
Boolean flag to enable or disable an API without deleting the row |
LAST_RUN_TS |
Timestamp of the last successful execution for incremental tracking |
Execution Log Table
The EXECUTION_LOG table captures the runtime status of every pipeline execution, providing complete observability:
CREATE TABLE EXECUTION_LOG (
LOG_ID INT AUTOINCREMENT,
API_NAME STRING,
TABLE_NAME STRING,
STATUS STRING,
START_TIME TIMESTAMP,
END_TIME TIMESTAMP,
ERROR_MESSAGE STRING
);
| Column | Description |
|---|---|
LOG_ID |
Auto-incrementing primary key for each log entry |
API_NAME |
Name of the API that was processed |
TABLE_NAME |
Target Snowflake table for this API |
STATUS |
Execution status: RUNNING, SUCCESS, or FAILED |
START_TIME |
Timestamp when the pipeline started processing this API |
END_TIME |
Timestamp when the processing completed or failed |
ERROR_MESSAGE |
Captured error message if the execution failed (NULL on success) |
Key Benefits
- Metadata-Driven Configuration: Add new REST APIs by simply inserting a row into the
API_METADATAtable. No pipeline modifications, no redeployment, and no code changes are required. - Full Error Handling with Execution Logging: Every pipeline run is tracked with start time, end time, status, and error messages. Each step's failure path logs that step's error, and a Fail activity after the logger makes failed APIs visible as failed runs.
- Dynamic Table Creation: The pipeline automatically creates Snowflake tables on first execution, eliminating the need for manual DDL scripts and reducing operational overhead.
- VARIANT Column Preserves Full JSON Structure: By storing API responses in Snowflake VARIANT columns, you preserve the complete JSON hierarchy. This allows flexible downstream querying using Snowflake dot notation and LATERAL FLATTEN without defining a rigid schema upfront.
- Time-Window Parameter for Incremental Loads: For APIs that accept a time filter,
LAST_RUN_TSand theEND_TSparameter define the window each run requests, and the success step moves the watermark forward. - Scalable and Maintainable: The ForEach pattern scales horizontally as you add more APIs. The separation of configuration from logic makes the pipeline easy to maintain and extend.
Conclusion
Building a metadata-driven Azure Data Factory pipeline for REST API ingestion into Snowflake provides a scalable, maintainable, and production-ready architecture for enterprise data integration. By storing API configurations in a metadata table, the pipeline eliminates hardcoded values and makes it trivial to onboard new data sources.
The combination of ADF's ForEach activity for parallel processing, ADLS Gen2 for intermediate JSON storage, and Snowflake's VARIANT data type for flexible semi-structured data handling creates a robust end-to-end data ingestion framework. The comprehensive execution logging with success and failure tracking ensures full observability and simplifies troubleshooting.
This pattern is particularly valuable for organizations that need to ingest data from dozens or hundreds of REST APIs, where maintaining individual pipelines for each source would be impractical. With this metadata-driven approach, your data engineering team can focus on data quality and analytics rather than pipeline maintenance.
One note for the future. Microsoft describes Data Factory in Microsoft Fabric as the next generation of ADF, and its upgrade guide points out that Fabric connections don't support dynamic properties. A metadata-driven design like this one would parameterise the connection object in Fabric instead of the linked service's base URL.
Frequently Asked Questions
Q: What is a metadata-driven pipeline in Azure Data Factory?
A metadata-driven pipeline reads its configuration (API URLs, table names, parameters) from a metadata table rather than hardcoding values. This allows you to add new data sources by inserting rows into the metadata table without modifying the pipeline. In this architecture, the API_METADATA table in Snowflake stores all API configurations, and the ADF Lookup activity reads these at runtime to drive the ForEach processing loop.
Q: Why use VARIANT columns in Snowflake for JSON data?
Snowflake's VARIANT data type natively stores semi-structured data like JSON. It preserves the full JSON structure and allows you to query nested fields using dot notation and LATERAL FLATTEN, eliminating the need to define a rigid schema upfront. This is especially useful for REST API responses where the JSON structure may vary between APIs or change over time without requiring table schema modifications.
Q: How does the pipeline handle API failures?
Each step that can fail has its own On Failure path to a logging Script Activity, which records that step's error and marks the status as FAILED in the EXECUTION_LOG table. One logger can't serve both steps through two On Failure lines, because ADF treats multiple dependencies as AND conditions, and the second step is skipped, not failed, when the first one fails. Add a Fail activity after each logger if failed APIs should show as failed pipeline runs.
Related Articles
Still have questions?
Get AssistanceReady? Let's Talk!
Get expert insights and answers tailored to your business requirements and transformation.
Get Assistance