# 顧客 更新

`PUT /v1/customers/{id}`

- operationId: `updateCustomer`
- tags: 顧客

IDで指定した顧客情報を更新します。


## コードサンプル

### cURL

```bash
curl \
    -X PUT \
    -H "Authorization:Bearer <Secret API Key>" \
    -H "Content-Type: application/json" \
    -d '{
    "name": "Jane Doe",
    "email": "jane@example.com"
}' \
'https://api.test.fincode.jp/v1/customers/{id}'
```

### Node.js

```javascript
import { createFincode } from "@fincode/node";

const API_KEY = "<Secret API Key>";

(async () => {
    const fincode = createFincode({ apiKey: API_KEY, isLiveMode: false });

    const customerId = "<Customer ID>";

    try {
        // リクエストの送信
        const customer = await fincode.customers.update(customerId, {
            name: "Jane Doe",
            email: "jane@example.com",
        });
    } catch (e) {
        // エラーの処理
    }
})();
```

### Go

```go
package main

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

func main() {

	apiKey := "<Secret API Key>"

	customerID := "<Customer ID>"
	body := UpdatingCustomerRequest{
		Name:  stringPointer("Jane Doe"),
		Email: stringPointer("jane@example.com"),
	}

	marshalledBody, _ := json.Marshal(body)

	// リクエストの作成
	req, _ := http.NewRequest(
		"PUT",
		fmt.Sprintf("https://api.test.fincode.jp/v1/customers/%s", customerID),
		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 UpdatingCustomerRequest struct {
	Name         *string `json:"name,omitempty"`
	Email        *string `json:"email,omitempty"`
	PhoneCC      *string `json:"phone_cc,omitempty"`
	PhoneNo      *string `json:"phone_no,omitempty"`
	AddrCity     *string `json:"addr_city,omitempty"`
	AddrCountry  *string `json:"addr_country,omitempty"`
	AddrLine1    *string `json:"addr_line_1,omitempty"`
	AddrLine2    *string `json:"addr_line_2,omitempty"`
	AddrLine3    *string `json:"addr_line_3,omitempty"`
	AddrPostCode *string `json:"addr_post_code,omitempty"`
	AddrState    *string `json:"addr_state,omitempty"`
}

func stringPointer(s string) *string {
	return &s
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';


$customerId = '<Customer ID>';

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

$data = json_encode([
    "name" => "Jane Doe",
    "email" => "jane@example.com"
]);

$session = curl_init();
curl_setopt($session, CURLOPT_URL, $baseUrl . $endpoint);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'PUT');
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>'

customer_id = '<Customer ID>'

url = f'https://api.test.fincode.jp/v1/customers/{customer_id}/'

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

data = {
    "name": "Jane Doe",
    "email": "jane@example.com"
}

# HTTP POSTリクエストの送信
try:
    response = requests.put(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
    customer_id = '<Customer ID>'
    endpoint = "/v1/customers/#{customer_id}"
    uri = URI.parse(BASE_URL + endpoint)

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

    data = {
        name: 'Jane Doe',
        email: 'jane@example.com',
    }

    # リクエストの作成
    request = Net::HTTP::Put.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
```

## パラメータ

| 名前 | 位置 | 必須 | 型 | 説明 |
| --- | --- | --- | --- | --- |
| `id` | path | ✓ | CustomerId_schema | 顧客ID |
| `Tenant-Shop-Id` | header |  | schema | <span class="smallText color--red-400">※ 顧客情報を共有しないプラットフォームのメインショップのみ指定可</span> |

## リクエストボディ

Content-Type: `application/json`

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `name` | name |  |  |
| `email` | email |  |  |
| `phone_cc` | phone_cc |  |  |
| `phone_no` | phone_no |  |  |
| `addr_country` | addr_country |  |  |
| `addr_state` | addr_state |  |  |
| `addr_city` | addr_city |  |  |
| `addr_line_1` | addr_line_1 |  |  |
| `addr_line_2` | addr_line_2 |  |  |
| `addr_line_3` | addr_line_3 |  |  |
| `addr_post_code` | addr_post_code |  |  |

## レスポンス

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

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `id` | string |  | 顧客ID |
| `name` | string |  | 顧客の名前 |
| `email` | string |  | 顧客のメールアドレス |
| `phone_cc` | string |  | 顧客の電話番号の国コード（`+`は含まない） |
| `phone_no` | string |  | 顧客の電話番号 |
| `addr_country` | string |  | 顧客の住所の国コード |
| `addr_state` | string |  | 顧客の住所の州コードまたは都道府県コード |
| `addr_city` | string |  | 顧客の住所の都市名 |
| `addr_line_1` | string |  | 顧客の住所の番地・区画 |
| `addr_line_2` | string |  | 顧客の住所の建物名・部屋番号 |
| `addr_line_3` | string |  | 顧客の住所 その他 |
| `addr_post_code` | string |  | 顧客の住所の郵便番号 |
| `card_registration` | enum(0 | 1) |  | 決済手段（カード）登録状況 |
| `directdebit_registration` | enum(0 | 1) |  | 決済手段（口座振替）登録状況 |
| `created` | created |  |  |
| `updated` | updated |  |  |

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

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

