# テナントショップ 審査ファイルアップロード

`POST /v1/contracts/examinations/tenants/{id}/files`

- operationId: `uploadExaminationFile`
- tags: テナント申請管理

`id`で指定したテナントショップの審査に必要なファイルのアップロードを行います。


## コードサンプル

### cURL

```bash
curl \
    -X POST \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: multipart/form-data" \
    -H "Tenant-Shop-Id: <Tenant Shop ID>" \
    -F "data=@<Path To File>;type=application/json;filename=\"<File Name>\"" \
    -F "type=DRIVER_LICENSE_FRONT"
'https://api.test.fincode.jp/v1/contracts/examinations/tenants/{Tenant Shop ID}/files'
```

### Node.js

```javascript
import fetch from "node-fetch";
import FormData from "form-data";
import * as fs from "fs";

const BASE_URL = "https://api.test.fincode.jp";

const API_KEY = "<Secret API Key>";

(async () => {
    const tenantShopId = "<Tenant Shop ID>";

    const endpoint = `${BASE_URL}/v1/contracts/examinations/tenants/${tenantShopId}/files`;

    const form = new FormData();

    // ファイル種別を指定（例として SALES_LICENSE_1: 販売免許証1）
    form.append("type", "SALES_LICENSE_1");

    // ファイルを指定
    const filePath = "<Path to File>";
    const fileName = "<File Name>";
    const file = fs.createReadStream(filePath);
    form.append("data", file, fileName);

    const response = await fetch(endpoint, {
        method: "POST",
        headers: {
            Authorization: `Bearer ${API_KEY}`,
            "Content-Type": `multipart/form-data; boundary=${form._boundary}`,
            "Tenant-Shop-Id": tenantShopId,
        },
        body: form,
    });
    const result = await response.json();
})();
```

### Go

```go
package main

import (
	"bytes"
	"fmt"
	"io"
	"log"
	"mime/multipart"
	"net/http"
	"os"
)

func main() {

	apiKey := "<Secret API Key>"

	tenantShopID := "<Tenant Shop ID>"

	// ファイルの読み込み
	filePath := "<Path To File>"
	fileName := "<File Name>"
	file, err := os.Open(filePath)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	// バッファの作成
	body := &bytes.Buffer{}
	writer := multipart.NewWriter(body)

	// ファイルの書き込み
	part, err := writer.CreateFormFile("data", fileName)
	if err != nil {
		log.Fatal(err)
	}
	_, err = io.Copy(part, file)
	if err != nil {
		log.Fatal(err)
	}

	// 追加情報（ファイル種別）の書き込み
	_ = writer.WriteField("type", "DRIVER_LICENSE_FRONT")

	// リクエストの作成
	req, _ := http.NewRequest("POST", fmt.Sprintf("https://api.test.fincode.jp/v1/contracts/examinations/tenants/%s/files", tenantShopID), body)
	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
	req.Header.Set("Content-Type", writer.FormDataContentType())
	req.Header.Set("Tenant-Shop-Id", tenantShopID)

	// リクエストの送信
	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>';

$tenantShopId = '<Tenant Shop ID>';

$baseUrl = "https://api.test.fincode.jp";
$endpoint = "/v1/contracts/examinations/tenants/{$tenantShopId}/files";
$headers = [
    "Authorization: Bearer " . $apiKey,
];

$filePath = '<Path to file>';
$fileName = '<File Name>';

// 販売免許等1 をアップロードする場合
$fields = [
    "data" => new CURLFile($filePath, null, $fileName),
    "type" => 'SALES_LICENSE_1',
];

$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, $fields);
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

def main():
    api_key = '<Secret API Key>'

    tenant_shop_id = '<Tenant Shop ID>'

    file_path = '<Path to file>'
    file_name = '<File Name>'

    with open(file_path, 'rb') as file:
        files = {'data': (file_name, file)}

        # 追加情報（ファイル種別）の指定
        payload = {'type': 'DRIVER_LICENSE_FRONT'}

        url = f'https://api.test.fincode.jp/v1/contracts/examinations/tenants/{tenant_shop_id}/files'

        # ヘッダーを設定
        headers = {
            'Authorization': f'Bearer {api_key}',
            'Tenant-Shop-Id': tenant_shop_id,
        }

        # HTTP POSTリクエストの送信
        try:
            response = requests.post(url, headers=headers, files=files, data=payload)

            # レスポンスの処理
            if response.status_code == 200:
                # 成功した場合の処理
                print(f"Success: {response.json()}")
            else:
                # エラーの処理
                print(f"Error: {response.json()} {response.text}")
        except requests.RequestException as e:
            # 通信エラーの処理
            print(f"Request error: {e}")

if __name__ == '__main__':
    main()
```

### Ruby

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


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

def main
    tenant_shop_id = '<Tenant Shop ID>'
    endpoint = "/v1/contracts/examinations/tenants/#{tenant_shop_id}/files"
    uri = URI.parse(BASE_URL + endpoint)

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

    file_path = '<Path to file>'
    file_name = '<File Name>'
    
    file = File.open(file_path, 'rb')
    file_data = file.read
    file.close

    # リクエストの作成
    request = Net::HTTP::Post.new(uri.request_uri)
    request['Authorization'] = "Bearer #{API_KEY}"
    request['Tenant-Shop-Id'] = tenant_shop_id

    # ファイルと追加情報をマルチパートフォームデータに追加
    boundary = '----MpbMultipartRequest'
    body = []
    insert_file_to_body(body, boundary, 'data', file_name, file_data)
    insert_data_to_body(body, boundary, 'type', "DRIVER_LICENSE_FRONT")
    body << "--#{boundary}--\r\n"

    request['Content-Type'] = "multipart/form-data; boundary=#{boundary}"
    request.body = body.join('')

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

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

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

def insert_file_to_body(body, boundary, key, file_name, file_data)
    body << "--#{boundary}\r\n"
    body << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{file_name}\"\r\n"
    body << "Content-Type: #{MIME::Types.type_for(file_name).first.content_type}\r\n"
    body << "\r\n"
    body << file_data
    body << "\r\n"
end

def insert_data_to_body(body, boundary, key, value)
    body << "--#{boundary}\r\n"
    body << "Content-Disposition: form-data; name=\"#{key}\"\r\n"
    body << "\r\n"
    body << value
    body << "\r\n"
end

main
```

## パラメータ

| 名前 | 位置 | 必須 | 型 | 説明 |
| --- | --- | --- | --- | --- |
| `id` | path | ✓ | schema | 指定したテナントショップのものとしてファイルをアップロードします。`Tenant-Shop-Id`ヘッダーも併せて指定してください。 |
| `Tenant-Shop-Id` | header | ✓ | schema | <span class="smallText color--red-400">※ プラットフォームのメインショップのみ指定可</span> |

## リクエストボディ

Content-Type: `multipart/form-data`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `type` | ExaminationFileType | ✓ |  |
| `data` | data | ✓ |  |

## レスポンス

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

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

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

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

