> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Using ClickHouse's HTTP interface to bring data from Azure Data Factory into ClickHouse

# Using ClickHouse HTTP interface in Azure data factory

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

The [`azureBlobStorage` Table Function](/reference/functions/table-functions/azureBlobStorage)
is a fast and convenient way to ingest data from Azure Blob Storage into
ClickHouse. Using it may however not always be suitable for the following reasons:

* Your data might not be stored in Azure Blob Storage — for example, it could be in Azure SQL Database, Microsoft SQL Server, or Cosmos DB.
* Security policies might prevent external access to Blob Storage
  altogether — for example, if the storage account is locked down with no public endpoint.

In such scenarios, you can use Azure Data Factory together with the
[ClickHouse HTTP interface](/concepts/features/interfaces/http)
to send data from Azure services into ClickHouse.

This method reverses the flow: instead of having ClickHouse pull the data from
Azure, Azure Data Factory pushes the data to ClickHouse. This approach
typically requires your ClickHouse instance to be accessible from the public
internet.

<Info>
  It is possible to avoid exposing your ClickHouse instance to the internet by
  using Azure Data Factory's Self-hosted Integration Runtime. This setup allows
  data to be sent over a private network. However, it's beyond the scope of this
  article. You can find more information in the official guide:
  [Create and configure a self-hosted integration
  runtime](https://learn.microsoft.com/en-us/azure/data-factory/create-self-hosted-integration-runtime?tabs=data-factory)
</Info>

<h2 id="turning-clickhouse-to-a-rest-service">
  Turning ClickHouse into a REST service
</h2>

Azure Data Factory supports sending data to external systems over HTTP in JSON
format. We can use this capability to insert data directly into ClickHouse
using the [ClickHouse HTTP interface](/concepts/features/interfaces/http).
You can learn more in the [ClickHouse HTTP Interface
documentation](/concepts/features/interfaces/http).

For this example, we only need to specify the destination table, define the
input data format as JSON, and include options to allow more flexible timestamp
parsing.

```sql theme={null}
INSERT INTO my_table
SETTINGS 
    date_time_input_format='best_effort',
    input_format_json_read_objects_as_strings=1
FORMAT JSONEachRow
```

To send this query as part of an HTTP request, you simply pass it as a
URL-encoded string to the query parameter in your ClickHouse endpoint:

```text theme={null}
https://your-clickhouse-url.com?query=INSERT%20INTO%20my_table%20SETTINGS%20date_time_input_format%3D%27best_effort%27%2C%20input_format_json_read_objects_as_strings%3D1%20FORMAT%20JSONEachRow%0A
```

<Info>
  Azure Data Factory can handle this encoding automatically using its built-in
  `encodeUriComponent` function, so you don't have to do it manually.
</Info>

Now you can send JSON-formatted data to this URL. The data should match the
structure of the target table. Here's a simple example using curl, assuming a
table with three columns: `col_1`, `col_2`, and `col_3`.

```text theme={null}
curl \
    -XPOST "https://your-clickhouse-url.com?query=<our_URL_encded_query>" \
    --data '{"col_1":9119,"col_2":50.994,"col_3":"2019-06-01 00:00:00"}'
```

You can also send a JSON array of objects, or JSON Lines (newline-delimited
JSON objects). Azure Data Factory uses the JSON array format, which works
perfectly with ClickHouse's `JSONEachRow` input.

As you can see, for this step you don't need to do anything special on the ClickHouse
side. The HTTP interface already provides everything needed to act as a
REST-like endpoint — no additional configuration required.

Now that we've made ClickHouse behave like a REST endpoint, it's time to
configure Azure Data Factory to use it.

In the next steps, we'll create an Azure Data Factory instance, set up a Linked
Service to your ClickHouse instance, define a Dataset for the
[REST sink](https://learn.microsoft.com/en-us/azure/data-factory/connector-rest),
and create a Copy Data activity to send data from Azure to ClickHouse.

<h2 id="create-an-azure-data-factory-instance">
  Creating an Azure data factory instance
</h2>

This guide assumes that you have access to Microsoft Azure account, and you
already have configured a subscription and a resource group. If you have
an Azure Data Factory already configured, then you can safely skip this step
and move to the next one using your existing service.

1. Log in to the [Microsoft Azure Portal](https://portal.azure.com/) and click
   **Create a resource**.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/azure-home-page.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=c48a4d09d703a10a84e727c737d083df" size="lg" alt="Azure Portal Home Page" border width="1271" height="674" data-path="images/integrations/data-ingestion/azure-data-factory/azure-home-page.png" />

2. In the Categories pane on the left, select **Analytics**, then click on
   **Data Factory** in the list of popular services.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/azure-new-resource-analytics.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=7a2c6fa93c7a50e0a59297d166b8d179" size="lg" alt="Azure Portal New Resource" border width="1271" height="593" data-path="images/integrations/data-ingestion/azure-data-factory/azure-new-resource-analytics.png" />

3. Select your subscription and resource group, enter a name for the new Data
   Factory instance, choose the region and leave the version as V2.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/azure-new-data-factory.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=ab5f3c8b43d33189cbe84864efb9e0a1" size="lg" alt="Azure Portal New Data Factory" border width="1271" height="674" data-path="images/integrations/data-ingestion/azure-data-factory/azure-new-data-factory.png" />

4. Click **Review + Create**, then click **Create** to launch the deployment.

   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/azure-new-data-factory-confirm.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=0fe78e808d18f22eb5d5dd14090f318b" size="lg" alt="Azure Portal New Data Factory Confirm" border width="1271" height="674" data-path="images/integrations/data-ingestion/azure-data-factory/azure-new-data-factory-confirm.png" />

   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/azure-new-data-factory-success.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=e65119c54897a48e323c348ff92c395b" size="lg" alt="Azure Portal New Data Factory Success" border width="1271" height="674" data-path="images/integrations/data-ingestion/azure-data-factory/azure-new-data-factory-success.png" />

Once the deployment completes successfully, you can start using your new Azure
Data Factory instance.

<h2 id="-creating-new-rest-based-linked-service">
  Creating a new REST-Based linked service
</h2>

1. Log in to the Microsoft Azure Portal and open your Data Factory instance.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/azure-home-with-data-factory.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=44df6efbda91bc3aab40aba3fcd87529" size="lg" alt="Azure Portal Home Page with Data Factory" border width="1271" height="674" data-path="images/integrations/data-ingestion/azure-data-factory/azure-home-with-data-factory.png" />

2. On the Data Factory overview page, click **Launch Studio**.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/azure-data-factory-page.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=9f43a2030cd77a048fe14bd3194e7981" size="lg" alt="Azure Portal Data Factory Page" border width="1271" height="674" data-path="images/integrations/data-ingestion/azure-data-factory/azure-data-factory-page.png" />

3. In the left-hand menu, select **Manage**, then go to **Linked services**,
   and click **+ New** to create a new linked service.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-create-linked-service-button.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=37f7d2ff848787be4040c3ccf695bffc" size="lg" alt="Azure Data Factory New Linked Service Button" border width="1271" height="674" data-path="images/integrations/data-ingestion/azure-data-factory/adf-create-linked-service-button.png" />

4. In the **New linked service search bar**, type **REST**, select **REST**, and click **Continue**
   to create [a REST connector](https://learn.microsoft.com/en-us/azure/data-factory/connector-rest)
   instance.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-search.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=d5ea746406f9e6adbc0218aae9238445" size="lg" alt="Azure Data Factory New Linked Service Search" border width="1271" height="674" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-search.png" />

5. In the linked service configuration pane enter a name for your new service,
   click the **Base URL** field, then click **Add dynamic content** (this link only
   appears when the field is selected).
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-lined-service-pane.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=2121b106d51e7a4cadb1c53724e07ba5" size="lg" alt="New Lined Service Pane" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-lined-service-pane.png" />

6. In the dynamic content pane you can create a parameterized URL, which
   allows you to define the query later when creating datasets for different
   tables — this makes the linked service reusable.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-base-url-empty.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=5a1dc995424f4a2b552bc9db6eaa0559" size="lg" alt="New Linked ServiceBase Url Empty" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-base-url-empty.png" />

7. Click the **"+"** next to the filter input and add a new parameter, name it
   `pQuery`, set the type to String, and set the default value to `SELECT 1`.
   Click **Save**.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-params.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=012444f056c02b1aeb50e8f626f6c0e5" size="lg" alt="New Linked Service Parameters" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-params.png" />

8. In the expression field, enter the following and click **OK**. Replace
   `your-clickhouse-url.com` with the actual address of your ClickHouse
   instance.
   ```text theme={null}
   @{concat('https://your-clickhouse-url.com:8443/?query=', encodeUriComponent(linkedService().pQuery))}
   ```
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-expression-field-filled.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=a6e1c56d55c91880a9984198a58e0a89" size="lg" alt="New Linked Service Expression Field Filled" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-expression-field-filled.png" />

9. Back in the main form select Basic authentication, enter the username and
   password used to connect to your ClickHouse HTTP interface, click **Test
   connection**. If everything is configured correctly, you'll see a success
   message.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-check-connection.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=ca3a774bec6e5ebdaab8bfdaa8032fdd" size="lg" alt="New Linked Service Check Connection" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-linked-service-check-connection.png" />

10. Click **Create** to finalize the setup.
    <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-linked-services-list.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=5d421ce1cb851bd357f1c7a6bc42b728" size="lg" alt="Linked Services List" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-linked-services-list.png" />

You should now see your newly registered REST-based linked service in the list.

<h2 id="creating-a-new-dataset-for-the-clickhouse-http-interface">
  Creating a new dataset for the ClickHouse HTTP Interface
</h2>

Now that we have a linked service configured for the ClickHouse HTTP interface,
we can create a dataset that Azure Data Factory will use to send data to
ClickHouse.

In this example, we'll insert a small portion of the [Environmental Sensors
Data](/get-started/sample-datasets/environmental-sensors).

1. Open the ClickHouse query console of your choice — this could be the
   ClickHouse Cloud web UI, the CLI client, or any other interface you use to
   run queries — and create the target table:
   ```sql theme={null}
   CREATE TABLE sensors
   (
       sensor_id UInt16,
       lat Float32,
       lon Float32,
       timestamp DateTime,
       temperature Float32
   )
   ENGINE = MergeTree
   ORDER BY (timestamp, sensor_id);
   ```

2. In Azure Data Factory Studio, select Author in the left-hand pane. Hover
   over the Dataset item, click the three-dot icon, and choose New dataset.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-item.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=eb90b549e3866a67c2f3f70eba9c07e0" size="lg" alt="New Dataset Item" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-item.png" />

3. In the search bar, type **REST**, select **REST**, and click **Continue**.
   Enter a name for your dataset and select the **linked service** you created
   in the previous step. Click **OK** to create the dataset.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-page.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=9deda4cba254f9a2a957805d09f3740f" size="lg" alt="New Dataset Page" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-page.png" />

4. You should now see your newly created dataset listed under the Datasets
   section in the Factory Resources pane on the left. Select the dataset to
   open its properties. You'll see the `pQuery` parameter that was defined in the
   linked service. Click the **Value** text field. Then click **Add dynamic**
   content.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-properties.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=75713bc9374bf1b5a8f84db5b5323812" size="lg" alt="New Dataset Properties" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-properties.png" />

5. In the pane that opens, paste the following query:
   ```sql theme={null}
   INSERT INTO sensors
   SETTINGS 
       date_time_input_format=''best_effort'', 
       input_format_json_read_objects_as_strings=1 
   FORMAT JSONEachRow
   ```

<Danger>
  All single quotes `'` in the query must be replaced with two single quotes
  `''`. This is required by Azure Data Factory's expression parser. If you
  don't escape them, you may not see an error immediately — but it will fail
  later when you try to use or save the dataset. For example, `'best_effort'`
  must be written as `''best_effort''`.
</Danger>

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-query.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=0ce0395366b5bf9f71d163047e927bad" size="xl" alt="New Dataset Query" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-query.png" />

6. Click OK to save the expression. Click Test connection. If everything is
   configured correctly, you'll see a Connection successful message. Click Publish
   all at the top of the page to save your changes.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-connection-successful.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=5534b1f97ef9116f37bd6984965959ba" size="xl" alt="New Dataset Connection Successful" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-dataset-connection-successful.png" />

<h3 id="setting-up-an-example-dataset">
  Setting up an example dataset
</h3>

In this example, we won't use the full Environmental Sensors Dataset, but
just a small subset available at the
[Sensors Dataset Sample](https://datasets-documentation.s3.eu-west-3.amazonaws.com/environmental/sensors.csv).

<Info>
  To keep this guide focused, we won't go into the exact steps for creating the
  source dataset in Azure Data Factory. You can upload the sample data to any
  storage service of your choice — for example, Azure Blob Storage, Microsoft SQL
  Server, or even a different file format supported by Azure Data Factory.
</Info>

Upload the dataset to your Azure Blob Storage (or another preferred storage
service), Then, in Azure Data Factory Studio, go to the Factory Resources pane.
Create a new dataset that points to the uploaded data. Click Publish all to
save your changes.

<h2 id="creating-the-copy-activity-to-transfer-data-to-clickhouse">
  Creating a Copy Activity to transfer data to ClickHouse
</h2>

Now that we've configured both the input and output datasets, we can set up a
**Copy Data** activity to transfer data from our example dataset into the
`sensors` table in ClickHouse.

1. Open **Azure Data Factory Studio**, go to the **Author tab**. In the
   **Factory Resources** pane, hover over **Pipeline**, click the three-dot
   icon, and select **New pipeline**.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-pipeline-item.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=6629386f3b1f01ed921e4e88998a12a5" size="lg" alt="ADF New Pipeline Item" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-pipeline-item.png" />

2. In the **Activities** pane, expand the **Move and transform** section and
   drag the **Copy data** activity onto the canvas.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-new-copy-data-item.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=dc9f73452cc873f760947e07a601c85b" size="lg" alt="New Copy DataItem" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-new-copy-data-item.png" />

3. Select the **Source** tab, and choose the source dataset you created earlier.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-copy-data-source.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=8d0a49d67150ba00afd1b4625bacf862" size="lg" alt="Copy Data Source" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-copy-data-source.png" />

4. Go to the **Sink** tab and select the ClickHouse dataset created for your
   sensors table. Set **Request method** to POST. Ensure **HTTP compression
   type** is set to **None**.

<Warning>
  HTTP compression doesn't work correctly in Azure Data Factory's Copy Data
  activity. When enabled, Azure sends a payload consisting of zero bytes only
  — likely a bug in the service. Be sure to leave compression disabled.
</Warning>

<Info>
  We recommend keeping the default batch size of 10,000, or even increasing it
  further. For more details, see
  [Selecting an Insert Strategy / Batch inserts if synchronous](/concepts/best-practices/selecting-an-insert-strategy#batch-inserts-if-synchronous)
  for more details.
</Info>

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-copy-data-sink-select-post.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=6485f5fe390037bec365235eff68a5f8" size="lg" alt="Copy Data Sink Select Post" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-copy-data-sink-select-post.png" />

5. Click **Debug** at the top of the canvas to run the pipeline. After a short
   wait, the activity will be queued and executed. If everything is configured
   correctly, the task should finish with a **Success** status.
   <Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/lGskH5qUgz9Vtlav/images/integrations/data-ingestion/azure-data-factory/adf-copy-data-debug-success.png?fit=max&auto=format&n=lGskH5qUgz9Vtlav&q=85&s=4d15c58da85b72871feaa633aaa27047" size="lg" alt="Copy Data Debug Success" border width="1158" height="765" data-path="images/integrations/data-ingestion/azure-data-factory/adf-copy-data-debug-success.png" />

6. Once complete, click **Publish all** to save your pipeline and dataset changes.

<h2 id="additional-resources-1">
  Additional resources
</h2>

* [HTTP Interface](/concepts/features/interfaces/http)
* [Copy and transform data from and to a REST endpoint by using Azure Data Factory](https://learn.microsoft.com/en-us/azure/data-factory/connector-rest?tabs=data-factory)
* [Selecting an Insert Strategy](/concepts/best-practices/selecting-an-insert-strategy)
* [Create and configure a self-hosted integration runtime](https://learn.microsoft.com/en-us/azure/data-factory/create-self-hosted-integration-runtime?tabs=data-factory)
