# テナントバイヤー 作成（新規ユーザー登録）

`POST /v1/buyer_platform/tenant_entries`

- operationId: `createTenantBuyerWithNewUser`
- tags: テナントバイヤー申請管理

新規ユーザーを作成し、作成されたユーザーをオーナーとして新規テナントバイヤーを作成するAPIです。\
このAPIでのテナントバイヤー作成に成功すると、登録されたメールアドレス宛にメールアドレス認証メールが送信されます。


## コードサンプル

### cURL

```bash
curl \
    -X POST \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: application/json" \
    -d '{
    "email": "<New User Email Address>",
    "password": "<New User Password>",
    "name": "<New User Name>",
    "tenant_url_id": "<Tenant Invitation URL ID>"
}' \
'https://api.test.fincode.jp/v1/buyer_platform/tenant_entries'
```

### Node.js

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

(async () => {
    const response = await fetch("https://api.test.fincode.jp/v1/buyer_platform/tenant_entries", {
        method: "POST",
        headers: {
            Authorization: `Bearer ${API_KEY}`,
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            email: "new-user@example.com",
            password: "new-user-password",
            name: "New User",
            tenant_url_id: "<Tenant Invitation URL ID>",
        }),
    });

    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 := CreatingTenantBuyerWithNewUserRequest{
		Email:       "new-user@example.com",
		Password:    "new-user-password",
		Name:        "New User",
		TenantURLID: "<Tenant Invitation URL ID>",
	}

	marshalledBody, _ := json.Marshal(body)

	req, _ := http.NewRequest("POST", "https://api.test.fincode.jp/v1/buyer_platform/tenant_entries", 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()
}

type CreatingTenantBuyerWithNewUserRequest struct {
	Email       string `json:"email"`
	Password    string `json:"password"`
	Name        string `json:"name"`
	TenantURLID string `json:"tenant_url_id"`
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';

$baseUrl = "https://api.test.fincode.jp";
$endpoint = "/v1/buyer_platform/tenant_entries";
$headers = [
    "Authorization: Bearer " . $apiKey,
    "Content-Type: application/json"
];

$data = json_encode([
    "email" => "new-user@example.com",
    "password" => "new-user-password",
    "name" => "New User",
    "tenant_url_id" => "<Tenant Invitation URL ID>",
]);

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

$response = curl_exec($session);

if ($response === false) {
    echo "cURL Error: " . curl_error($session);
} else {
    var_dump($response);
}

curl_close($session);
```

### Python 3

```python
import requests

api_key = '<Secret API Key>'

url = 'https://api.test.fincode.jp/v1/buyer_platform/tenant_entries'

headers = {
    'Authorization': f'Bearer {api_key}',
    'Content-Type': 'application/json'
}

data = {
    'email': 'new-user@example.com',
    'password': 'new-user-password',
    'name': 'New User',
    'tenant_url_id': '<Tenant Invitation URL ID>'
}

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

    if response.status_code == 200:
        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/buyer_platform/tenant_entries'

    uri = URI.parse(BASE_URL + endpoint)

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

    data = {
        email: 'new-user@example.com',
        password: 'new-user-password',
        name: 'New User',
        tenant_url_id: '<Tenant Invitation URL ID>'
    }

    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`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `email` | email | ✓ |  |
| `password` | password | ✓ |  |
| `name` | name | ✓ |  |
| `tenant_buyer_url_id` | tenant_buyer_url_id | ✓ |  |

## レスポンス

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

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `user_data` | User |  | 新規作成されたユーザー情報（このAPIによって新規作成されたテナントのショップIDを含む） |
| `access_token` | string |  | アクセストークン |
| `authorities` | array<object> |  | ユーザーの権限情報 |

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

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

