> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.tiankii.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.tiankii.com/_mcp/server.

# Link products to modifier

POST https://api.md.tiankii.com/v1/product-modifiers/products/link
Content-Type: application/json

## Link products to a modifier

Sets the **complete list of products** a modifier applies to. The supplied `productIds` array is the desired final state: every existing link for the modifier is deleted and then recreated from the array.

### Authentication

* Merchant API key in **`x-api-key`** (alias `x-account-api-key`).
* Requires **`Merchant.product.update`**.

### Body (application/json)

* `modifierId` (required) — UUID of the modifier. Must belong to your store, otherwise **400 Bad Request** (`Modifier not found in yours`).
* `productIds` (required) — non-empty array of unique product UUIDs. Every id must belong to your store, otherwise **403 Forbidden** (`Some products do not belong to your store`).

### Behavior & side-effects

* Runs in a single transaction: `deleteMany({ modifierId })` followed by `createMany` with `skipDuplicates`.
* Because it replaces the set, sending a product list that omits a currently linked product **unlinks** it.
* Returns `{ message: "Products linked to modifier successfully" }`.

***

**Notas:** Handler: productModifiersService.linkProductsForModifier. Replacement semantics, not incremental. Duplicated ids in the payload are de-duplicated before the ownership check (@ArrayUnique also rejects duplicates at validation time).

Reference: https://docs.tiankii.com/api-reference/tiankii-api-api-key/products/modifiers/link-products

## Authentication

- `x-api-key` header (required)

## Request

### Headers

- `x-application-account-id` (string, optional) — Scope the request to a specific store / account instead of the one resolved from the API key. Aliases: the `x-account-id` header, or the `application_account_id` / `account_id` query parameter.

### Body (application/json)

- `modifierId` (string, required)
- `productIds` (list of string, required)

## Examples

**Request**

```json
{
  "modifierId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "productIds": [
    "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
    "d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a"
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api.md.tiankii.com/v1/product-modifiers/products/link"

payload = {
    "modifierId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
    "productIds": ["c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f", "d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a"]
}
headers = {
    "x-application-account-id": "acct_3f9a21c7",
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.md.tiankii.com/v1/product-modifiers/products/link';
const options = {
  method: 'POST',
  headers: {
    'x-application-account-id': 'acct_3f9a21c7',
    'x-api-key': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"modifierId":"a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d","productIds":["c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f","d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.md.tiankii.com/v1/product-modifiers/products/link"

	payload := strings.NewReader("{\n  \"modifierId\": \"a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d\",\n  \"productIds\": [\n    \"c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f\",\n    \"d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-application-account-id", "acct_3f9a21c7")
	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.md.tiankii.com/v1/product-modifiers/products/link")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-application-account-id"] = 'acct_3f9a21c7'
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"modifierId\": \"a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d\",\n  \"productIds\": [\n    \"c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f\",\n    \"d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.md.tiankii.com/v1/product-modifiers/products/link")
  .header("x-application-account-id", "acct_3f9a21c7")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"modifierId\": \"a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d\",\n  \"productIds\": [\n    \"c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f\",\n    \"d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a\"\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.md.tiankii.com/v1/product-modifiers/products/link', [
  'body' => '{
  "modifierId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "productIds": [
    "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
    "d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a"
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
    'x-application-account-id' => 'acct_3f9a21c7',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.md.tiankii.com/v1/product-modifiers/products/link");
var request = new RestRequest(Method.POST);
request.AddHeader("x-application-account-id", "acct_3f9a21c7");
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"modifierId\": \"a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d\",\n  \"productIds\": [\n    \"c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f\",\n    \"d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "x-application-account-id": "acct_3f9a21c7",
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "modifierId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "productIds": ["c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f", "d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.md.tiankii.com/v1/product-modifiers/products/link")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```