# テナントショップ 一括適用

`POST /v1/tenants/bulk_apply`

- operationId: `bulkApplyTenantShop`
- tags: テナントショップ

配下のテナントショップのプラットフォーム利用料（月末または入金）を、一括で変更（上書き）します。\
変更の対象は`apply_all_flag`で指定します。

- `1`: 配下のすべてのテナントショップを、標準プラットフォーム利用料で上書きします。
- `0`（省略時）: `target_fee`で指定した金額が設定されているテナントショップのみを、`new_fee`で指定した金額に変更します。

適用する値と同じ値のテナントショップは更新されません。解約済みのテナントショップは対象外です。\
\
プラットフォーム（メインショップ）のAPIキーで、オーナーまたは管理者ロールのユーザーが実行できます。\
対象のテナントショップがない場合も、`updated_count`が`0`でリクエストは成功します。


## コードサンプル

### cURL

```bash
curl \
    -X POST \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: application/json" \
    -d '{
    "examination_master_id": "9911",
    "target_fee": 1500,
    "new_fee": 1000
}' \
'https://api.test.fincode.jp/v1/tenants/bulk_apply'
```

### Node.js

```javascript
const API_KEY = "<Secret API Key>";

(async () => {
    const response = await fetch("https://api.test.fincode.jp/v1/tenants/bulk_apply", {
        method: "POST",
        headers: {
            Authorization: `Bearer ${API_KEY}`,
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            examination_master_id: "9911",
            target_fee: 1500,
            new_fee: 1000,
        }),
    });

    const data = await response.json();
    console.log(data);
})();
```

### Go

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
)

func main() {

	apiKey := "<Secret API Key>"

	body := map[string]interface{}{
		"examination_master_id": "9911",
		"target_fee":            1500,
		"new_fee":               1000,
	}

	marshalledBody, _ := json.Marshal(body)

	// リクエストの作成
	req, _ := http.NewRequest(
		"POST",
		"https://api.test.fincode.jp/v1/tenants/bulk_apply",
		bytes.NewBuffer(marshalledBody),
	)
	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
	req.Header.Set("Content-Type", "application/json")

	// リクエストの送信
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';

$baseUrl = "https://api.test.fincode.jp";
$endpoint = "/v1/tenants/bulk_apply";

$headers = [
    "Authorization: Bearer " . $apiKey,
    "Content-Type: application/json"
];

$data = json_encode([
    "examination_master_id" => "9911",
    "target_fee" => 1500,
    "new_fee" => 1000,
]);

$session = curl_init();
curl_setopt($session, CURLOPT_URL, $baseUrl . $endpoint);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $data);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($session, CURLOPT_SSL_VERIFYPEER, );
// curl_setopt($session, CURLOPT_SSL_VERIFYHOST, );

$response = curl_exec($session);

if ($response === false) {
    # エラー処理
    echo "cURL Error: " . curl_error($session);
} else {
    # APIからのデータを処理
    var_dump($response);
}

curl_close($session);
```

### Python 3

```python
import requests

api_key = '<Secret API Key>'

url = f'https://api.test.fincode.jp/v1/tenants/bulk_apply'

# ヘッダーを設定
headers = {
    'Authorization': f'Bearer {api_key}',
    'Content-Type': 'application/json'
}

data = {
    "examination_master_id": "9911",
    "target_fee": 1500,
    "new_fee": 1000,
}

try:
    response = requests.post(url, headers=headers, json=data)

    # レスポンスの処理
    if response.status_code == 200:
        # APIからのデータを処理
        print(f"Success: {response.json()}")
    else:
        # エラーの処理
        print(f"Error: {response.json()}")
except requests.RequestException as e:
    # 通信エラーの処理
    print(f"Request error: {e}")
```

### Ruby

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

API_KEY = '<Secret API Key>'
BASE_URL = 'https://api.test.fincode.jp'

def main
    endpoint = "/v1/tenants/bulk_apply"

    uri = URI.parse(BASE_URL + endpoint)

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

    data = {
        examination_master_id: "9911",
        target_fee: 1500,
        new_fee: 1000
    }

    # リクエストの作成
    request = Net::HTTP::Post.new(uri.request_uri)
    request['Authorization'] = "Bearer #{API_KEY}"
    request['Content-Type'] = 'application/json'

    request.body = data.to_json

    # リクエストの送信
    response = http.request(request)

    case response
    when Net::HTTPSuccess
        puts 'SUCCESS'
    else
        puts 'ERROR'
    end

    # レスポンスの表示
    puts response.body
end

main
```

## リクエストボディ

Content-Type: `application/json`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `examination_master_id` | enum(9911 | 9912) | ✓ | 一括適用の対象とするプラットフォーム利用料の種別。 |
| `apply_all_flag` | enum(0 | 1) |  | 一括適用の対象とするテナントショップの範囲。 |
| `target_fee` | integer |  | 変更の対象とするプラットフォーム利用料の金額（税抜・円）。この金額が設定されているテナントショップのみが対象です。 |
| `new_fee` | integer |  | 変更後のプラットフォーム利用料の金額（税抜・円）。 |

## レスポンス

### 200 リクエストに成功

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `examination_master_id` | enum(9911 | 9912) |  | リクエストで指定した、一括適用の対象とするプラットフォーム利用料の種別 |
| `applied_fee` | integer |  | 適用したプラットフォーム利用料（税抜・円）。 |
| `updated_count` | integer |  | 値を更新したテナントショップの数。 |

### 400 不正なリクエスト

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `errors` | array<FincodeAPIError> |  |  |

