# インボイス 削除

`DELETE /v1/invoices/{id}`

- operationId: `deleteInvoices`
- tags: インボイス機能

指定したIDを持つ、下書き状態のインボイス情報を削除します。\
発行済みのインボイス情報は削除できません。


## コードサンプル

### cURL

```bash
curl \
    -X DELETE \
    -H "Authorization:Bearer <Secret API Key>" \
'https://api.test.fincode.jp/v1/invoices/{id}'
```

### Node.js

```javascript
import fetch from "node-fetch";

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

(async () => {
    const invoiceId = "<Invoice ID>"; // 実際のInvoice IDを設定

    const endpoint = `${BASE_URL}/v1/invoices/${invoiceId}`;

    const response = await fetch(endpoint, {
        method: "DELETE",
        headers: {
            Authorization: `Bearer ${API_KEY}`,
        },
    });

    if (response.ok) {
        const result = await response.json();
        console.log('削除成功:', result);
    } else {
        console.error('削除に失敗しました:', await response.text());
    }
})();
```

### Go

```go
package main

import (
	"fmt"
	"log"
	"net/http"
)

func main() {
	// APIキーとインボイスIDを指定
	apiKey := "<Secret API Key>"
	invoiceID := "<Invoice ID>" // 削除するインボイスIDを指定

	// リクエストの作成
	req, err := http.NewRequest(
		"DELETE",
		fmt.Sprintf("https://api.test.fincode.jp/v1/invoices/%s", invoiceID),
		nil,
	)
	if err != nil {
		log.Fatalf("リクエストの作成エラー: %v", err)
	}

	// ヘッダーの設定
	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))

	// クライアントの作成とリクエストの送信
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		log.Fatalf("リクエストエラー: %v", err)
	}
	defer res.Body.Close()

	// HTTPステータスコードを表示
	fmt.Println("HTTPステータスコード:", res.StatusCode)
}
```

### PHP

```php
<?php

$apiKey = '<Secret API Key>';
$invoiceId = '<Invoice ID>'; // 実際のInvoice IDを設定

$baseUrl = "https://api.test.fincode.jp";
$endpoint = "/v1/invoices/{$invoiceId}";

$headers = [
    "Authorization: Bearer " . $apiKey,
];

$session = curl_init();
curl_setopt($session, CURLOPT_URL, $baseUrl . $endpoint);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$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>'
invoice_id = '<Invoice ID>'  # 実際のInvoice IDを設定

url = f'https://api.test.fincode.jp/v1/invoices/{invoice_id}'

# ヘッダーを設定
headers = {
    'Authorization': f'Bearer {api_key}',
}

try:
    response = requests.delete(url, headers=headers)

    # レスポンスの処理
    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
  invoice_id = '<Invoice ID>' # 実際のInvoice IDを設定

  endpoint = "/v1/invoices/#{invoice_id}"

  uri = URI.parse(BASE_URL + endpoint)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

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

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

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

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

main
```

## パラメータ

| 名前 | 位置 | 必須 | 型 | 説明 |
| --- | --- | --- | --- | --- |
| `Tenant-Shop-Id` | header |  | schema | <span class="smallText color--red-400">※ プラットフォームのメインショップのみ指定可</span> |
| `id` | path | ✓ | string | インボイスID |

## レスポンス

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

| パラメータ | 型 | 必須 | 説明 |
| --- | --- | --- | --- |
| `id` | string |  | インボイスID |
| `delete_flag` | string |  | 削除フラグ |

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

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

