# 加工部品API

加工部品の一覧、作成、更新、削除、検索。

Source: https://support.toolingmetrics.com/ja/api/reference/parts/
Updated: 2026-10-29

ベースパス：`/v1/organizations/:organization_id/parts`

<a id="endpoints"></a>

## エンドポイント

| メソッド | パス | 説明 |
|---|---|---|
| `GET` | `/parts` | すべての加工部品の一覧 |
| `GET` | `/parts/:id` | 加工部品を取得 |
| `POST` | `/parts` | 加工部品を作成 |
| `PATCH` | `/parts/:id` | 加工部品を更新 |
| `DELETE` | `/parts/:id` | 加工部品を削除 |
| `GET` | `/parts/search` | 部品番号、説明、またはその両方で検索 |

<a id="part-object"></a>

## 加工部品オブジェクト

```json
{
  "id": 5,
  "number": "P-0042",
  "description": "Cylinder Block",
  "customer_number": "CB-100",
  "created_at": "2025-03-01T08:00:00Z",
  "updated_at": "2025-06-01T10:00:00Z",
  "material": {
    "id": 2,
    "name": "42CrMo4",
    "iso_code": "P20",
    "vdi_code": "1.7225"
  },
  "created_by": { "id": 7, "email": "user@example.com" }
}
```

<a id="parameters"></a>

## パラメータ

<a id="create--update"></a>

### 作成・更新

| パラメータ | 型 | 説明 |
|---|---|---|
| `number` | string | 部品番号。作成時に空の場合は、組織の加工部品の採番設定から自動生成します。 |
| `description` | string | 加工部品の説明 |
| `customer_number` | string | 顧客側の参照番号 |
| `material_id` | integer | 材料ライブラリの材料ID。組織自身の材料か共有の材料です。別の組織の材料には`422`を返します |
| `organization_id` | integer | URLだけでなく、**作成時は本文にも必須**です。`:organization_id`のパス要素は権限を確認しますが、それだけで新しい加工部品を組織に関連付けるわけではありません。本文でも指定してください。 |
| `user_id` | integer | 権限によるアクセス範囲のため、特定のユーザーに関連付けます。[認証](https://support.toolingmetrics.com/ja/api/authentication/)を参照してください。必要と分かっている場合以外は指定しません。 |
| `picture` | string | Base64エンコードしたPNGの加工部品の写真 |
| `drawing` | string | Base64エンコードしたDXFの2D図面 |
| `model` | string | Base64エンコードしたSTEPの3Dモデル |

<a id="search"></a>

### 検索

| パラメータ | 型 | 説明 |
|---|---|---|
| `number` | string | 部品番号の完全一致 |
| `description` | string | 大文字・小文字を区別しない説明の完全一致 |

両方のパラメータを組み合わせて絞り込めます。

<a id="file-attachments"></a>

## 添付ファイル

写真、図面、STEPモデルは、JSON本文内のBase64エンコード文字列でアップロードします。ファイルはオブジェクトストレージに保存され、保存後に加工部品のレコードに関連付けられます。

```json
{
  "number": "P-0042",
  "description": "Cylinder Block",
  "model": "<base64-encoded-step-content>"
}
```

<a id="examples"></a>

## 使用例

```bash
# Search by part number
curl "https://api.toolingmetrics.com/v1/organizations/12/parts/search?number=P-0042" \
  -H "Authorization: Bearer YOUR_TOKEN"

# Create a part — organization_id is required in the body, not just the URL
curl -X POST "https://api.toolingmetrics.com/v1/organizations/12/parts" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"number": "P-0042", "description": "Cylinder Block", "material_id": 2, "organization_id": 12}'
```

```python
import requests
import base64

BASE = "https://api.toolingmetrics.com/v1"
HEADERS = {"Authorization": "Bearer YOUR_TOKEN"}

# Create a part with a STEP model attached
with open("cylinder_block.stp", "rb") as f:
    model_b64 = base64.b64encode(f.read()).decode()

response = requests.post(
    f"{BASE}/organizations/12/parts",
    headers={**HEADERS, "Content-Type": "application/json"},
    json={
        "number": "P-0042",
        "description": "Cylinder Block",
        "material_id": 2,
        "organization_id": 12,
        "model": model_b64,
    },
)
response.raise_for_status()
part = response.json()
print(f"Created part #{part['id']}: {part['number']}")
```
