> ## Documentation Index
> Fetch the complete documentation index at: https://docs.frictio.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create contact record

> Contact を1件作成します。このエンドポイントは Contact 専用です。他のオブジェクトの作成には対応していません。

**利用条件**
- APIキーに紐づくサービスアカウントのロールに、Contact の作成権限と閲覧権限（ワークスペース全体）が必要です
- サービスアカウントに紐づく APIキーが必要です。サービスアカウントに紐づかない従来の APIキーは、読み取りでは使えても作成では `401`（`INVALID_API_KEY`）になります
- Contact のレコード機能が有効なワークスペースだけで利用できます。有効でないワークスペースでは `503`（`CONTACT_WRITE_UNAVAILABLE`）を返します

**リクエストの形式**
- 本文は `Content-Type: application/json`（`charset=utf-8` のパラメータは付けられます）の JSON オブジェクトで送信してください。`application/x-www-form-urlencoded`、`text/plain` など JSON 以外の形式や、`Content-Type` を付けない本文（`Transfer-Encoding: chunked` を含む）は `415`（`UNSUPPORTED_MEDIA_TYPE`）になり、処理は実行されません
- `Content-Type` を付けず本文も空のリクエストは `415` ではなく `400`（`VALIDATION_FAILED`）です

**重複と再送**
- 同じメールアドレス（大文字小文字は区別しません）の有効な Contact がすでにある場合は `409`（`CONTACT_EMAIL_CONFLICT`）を返します。メールアドレスでの更新（Upsert）や、`409` のあとの自動更新は行いません。既存の Contact は `PATCH` で更新してください
- `Idempotency-Key` ヘッダーには対応していません
- 作成した Contact は全体公開（`visibility` が `workspace`）で、担当者（owner）は設定されません。公開日時（`published_at`）は作成時刻に設定されます
- 作成は1つのトランザクションで完結しません。Contact 本体の作成後に別の書き込みで失敗すると、Contact は存在するのにエラー（`502`）が返り、公開・所有に関する情報や従来の読み取り処理向けの情報が反映されないまま残ることがあります
- `502` / `504` / タイムアウトの時点では、作成の結果は不明です。自動で再送しないでください。再送して `409` が返った場合は、成功とは扱わず結果の確認が必要です
- `503`（`WORKSPACE_UNDER_MAINTENANCE`）が返った場合も、まれに Contact が作成済みのことがあります。そのあとの再送で `409` が返った場合は、同じく結果を確認してください
- Contact の検索（メールアドレスでの絞り込み）には対応していないため、結果は Frictio 上で確認してください
- 大文字小文字だけが違うメールアドレスをほぼ同時に作成すると、重複した Contact が作られる場合があります。同じメールアドレスのリクエストは並列に送らないでください

**副作用**
- 変更履歴の記録、Created Activity の記録（ベストエフォート。失敗してもリクエストは成功します）
- 連携している CRM（HubSpot / Salesforce）への送信キューへの登録

レスポンスは、直後の `GET /v2/objects/contact/records/{recordId}` と同じ内容です。`created_by` / `updated_by` は `{ "kind": "api_key", "name": "<サービスアカウント名>" }` で、ID は含まれません。
`fields` では、`first_name` / `last_name` は `name`（`{ "firstName", "lastName" }`）に入り、指定しない（`null` を含む）と空文字です。`phone_number` / `mobile_phone_number` / `job_title` / `department` は同じ名前のキーで返り、指定しない（`null`・空文字を含む）と `null` です。




## OpenAPI

````yaml /openapi.yaml post /v2/objects/contact/records
openapi: 3.1.0
info:
  title: Frictio Public API
  version: 1.0.0-beta
servers:
  - url: https://public-api.frictio.ai
security:
  - ApiKeyAuth: []
paths:
  /v2/objects/contact/records:
    post:
      summary: Create contact record
      description: >
        Contact を1件作成します。このエンドポイントは Contact 専用です。他のオブジェクトの作成には対応していません。


        **利用条件**

        - APIキーに紐づくサービスアカウントのロールに、Contact の作成権限と閲覧権限（ワークスペース全体）が必要です

        - サービスアカウントに紐づく APIキーが必要です。サービスアカウントに紐づかない従来の APIキーは、読み取りでは使えても作成では
        `401`（`INVALID_API_KEY`）になります

        - Contact のレコード機能が有効なワークスペースだけで利用できます。有効でないワークスペースでは
        `503`（`CONTACT_WRITE_UNAVAILABLE`）を返します


        **リクエストの形式**

        - 本文は `Content-Type: application/json`（`charset=utf-8` のパラメータは付けられます）の
        JSON オブジェクトで送信してください。`application/x-www-form-urlencoded`、`text/plain` など
        JSON 以外の形式や、`Content-Type` を付けない本文（`Transfer-Encoding: chunked` を含む）は
        `415`（`UNSUPPORTED_MEDIA_TYPE`）になり、処理は実行されません

        - `Content-Type` を付けず本文も空のリクエストは `415` ではなく `400`（`VALIDATION_FAILED`）です


        **重複と再送**

        - 同じメールアドレス（大文字小文字は区別しません）の有効な Contact がすでにある場合は
        `409`（`CONTACT_EMAIL_CONFLICT`）を返します。メールアドレスでの更新（Upsert）や、`409`
        のあとの自動更新は行いません。既存の Contact は `PATCH` で更新してください

        - `Idempotency-Key` ヘッダーには対応していません

        - 作成した Contact は全体公開（`visibility` が
        `workspace`）で、担当者（owner）は設定されません。公開日時（`published_at`）は作成時刻に設定されます

        - 作成は1つのトランザクションで完結しません。Contact 本体の作成後に別の書き込みで失敗すると、Contact
        は存在するのにエラー（`502`）が返り、公開・所有に関する情報や従来の読み取り処理向けの情報が反映されないまま残ることがあります

        - `502` / `504` / タイムアウトの時点では、作成の結果は不明です。自動で再送しないでください。再送して `409`
        が返った場合は、成功とは扱わず結果の確認が必要です

        - `503`（`WORKSPACE_UNDER_MAINTENANCE`）が返った場合も、まれに Contact
        が作成済みのことがあります。そのあとの再送で `409` が返った場合は、同じく結果を確認してください

        - Contact の検索（メールアドレスでの絞り込み）には対応していないため、結果は Frictio 上で確認してください

        - 大文字小文字だけが違うメールアドレスをほぼ同時に作成すると、重複した Contact
        が作られる場合があります。同じメールアドレスのリクエストは並列に送らないでください


        **副作用**

        - 変更履歴の記録、Created Activity の記録（ベストエフォート。失敗してもリクエストは成功します）

        - 連携している CRM（HubSpot / Salesforce）への送信キューへの登録


        レスポンスは、直後の `GET /v2/objects/contact/records/{recordId}`
        と同じ内容です。`created_by` / `updated_by` は `{ "kind": "api_key", "name":
        "<サービスアカウント名>" }` で、ID は含まれません。

        `fields` では、`first_name` / `last_name` は `name`（`{ "firstName",
        "lastName" }`）に入り、指定しない（`null` を含む）と空文字です。`phone_number` /
        `mobile_phone_number` / `job_title` / `department`
        は同じ名前のキーで返り、指定しない（`null`・空文字を含む）と `null` です。
      operationId: createV2ContactRecord
      parameters:
        - $ref: '#/components/parameters/workspaceId'
        - $ref: '#/components/parameters/writeRequestId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateContactRecordRequest'
            example:
              email: taro.yamada@example.com
              first_name: 太郎
              last_name: 山田
              phone_number: 03-1234-5678
              job_title: 営業部長
              department: 営業部
      responses:
        '201':
          description: 作成しました
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2ObjectRecord'
        '400':
          description: >
            リクエストが不正です。リクエスト本文が JSON として読めない場合も含め、Frictio Public API が返す場合の
            `error.code` は `VALIDATION_FAILED` です。

            必須項目（`email`）の不足、形式の不正、電話番号の不正、未知の項目の指定、`Content-Type`
            も本文もないリクエストが対象です。

            `X-Workspace-Id` が未指定、または APIキーのワークスペースと一致しない場合は、本文なしの `400`
            を返します。この場合は `VALIDATION_FAILED` の v2 形式ではなく、作成は実行されません。
          headers:
            X-Request-Id:
              $ref: '#/components/headers/RequestId'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2ContactWriteError'
              example:
                error:
                  code: VALIDATION_FAILED
                  message: 'Unknown properties: company_ids'
                  request_id: req-1
        '401':
          $ref: '#/components/responses/V2Unauthorized'
        '403':
          $ref: '#/components/responses/V2ContactWriteForbidden'
        '409':
          $ref: '#/components/responses/V2ContactWriteConflict'
        '413':
          $ref: '#/components/responses/V2ContactWritePayloadTooLarge'
        '415':
          $ref: '#/components/responses/V2ContactWriteUnsupportedMediaType'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '502':
          $ref: '#/components/responses/V2ContactWriteBadGateway'
        '503':
          $ref: '#/components/responses/V2ContactWriteServiceUnavailable'
        '504':
          $ref: '#/components/responses/V2ContactWriteGatewayTimeout'
components:
  parameters:
    workspaceId:
      name: X-Workspace-Id
      in: header
      required: true
      description: ワークスペースID
      schema:
        type: string
      example: e1f2a3b4-...
    writeRequestId:
      name: X-Request-Id
      in: header
      required: false
      description: >
        リクエストを識別する任意のIDです。指定した値がそのままレスポンスの `X-Request-Id` と、エラー時の
        `error.request_id` に使われます。

        指定しない場合は Frictio が採番します。
      schema:
        type: string
      example: req-1
  schemas:
    CreateContactRecordRequest:
      type: object
      description: >
        Contact の作成リクエストです。下記の7項目だけを指定できます。

        これ以外の項目（`company_ids`、`owner_id`、`visibility`、カスタム項目など）を含めると `400`
        を返し、無視はされません。

        作成した Contact の公開範囲は常に `workspace`（全体公開）で、担当者（owner）は設定されません。
      additionalProperties: false
      required:
        - email
      properties:
        email:
          type: string
          description: >
            メールアドレスです。必須です。空白を含まず、`@` がちょうど 1 つ（先頭以外）で、`@` より後ろに `.` が 1
            つ以上ある値を指定してください。その `.` は、`@` の直後と末尾以外の位置に必要です。それ以外は `400` になります。

            同じメールアドレス（大文字小文字は区別しません）の有効な Contact がワークスペースに存在する場合は `409` を返します。
          example: taro.yamada@example.com
        first_name:
          type:
            - string
            - 'null'
          description: 名。省略または `null` の場合は空文字になります（レスポンスでは `fields.name.firstName`）。
          example: 太郎
        last_name:
          type:
            - string
            - 'null'
          description: 姓。省略または `null` の場合は空文字になります（レスポンスでは `fields.name.lastName`）。
          example: 山田
        phone_number:
          type:
            - string
            - 'null'
          description: >-
            電話番号。先頭の `+`（任意）に続けて、数字・`(` `)` `.` `-`・空白だけの7〜20文字で指定します。それ以外の形式は
            `400` になります。省略・`null`・空文字の場合は未設定（`null`）になります。
          example: 03-1234-5678
        mobile_phone_number:
          type:
            - string
            - 'null'
          description: >-
            携帯電話番号。先頭の `+`（任意）に続けて、数字・`(` `)` `.` `-`・空白だけの7〜20文字で指定します。それ以外の形式は
            `400` になります。省略・`null`・空文字の場合は未設定（`null`）になります。
          example: 090-1234-5678
        job_title:
          type:
            - string
            - 'null'
          description: 役職。省略・`null`・空文字の場合は未設定（`null`）になります。
          example: 営業部長
        department:
          type:
            - string
            - 'null'
          description: 部署。省略・`null`・空文字の場合は未設定（`null`）になります。
          example: 営業部
    V2ObjectRecord:
      type: object
      required:
        - id
        - object
        - visibility
        - fields
        - created_at
        - updated_at
        - created_by
        - updated_by
      properties:
        id:
          type: string
        object:
          type: string
          description: |
            レコードが属する CRM オブジェクトの API 識別子です。
            値は `GET /v2/objects` のレスポンスに含まれる `data[].name` に対応します。
          example: deal
        visibility:
          type: string
          description: |
            レコードの公開範囲です。現在の read API は `workspace` のレコードのみを返します。
          enum:
            - workspace
            - restricted
          example: workspace
        fields:
          type: object
          description: |
            各キーはオブジェクトメタデータの `fields[].name` に対応します。
            標準フィールドとカスタムフィールドを含み、値の型はフィールドメタデータによって異なります。
            `MANY_TO_ONE` リレーションは `*_id` 形式のキーで表現されます。
          additionalProperties: true
          example:
            name: Acme
            pipeline_id: pipe-1
            amount: '1200.50'
            my_note: hello
        created_at:
          type:
            - string
            - 'null'
        updated_at:
          type:
            - string
            - 'null'
        created_by:
          oneOf:
            - $ref: '#/components/schemas/V2Actor'
            - type: 'null'
        updated_by:
          oneOf:
            - $ref: '#/components/schemas/V2Actor'
            - type: 'null'
    V2ContactWriteError:
      type: object
      description: >
        Contact の作成・更新が返す v2 エラー形式です。`request_id` は常に含まれ、レスポンスヘッダー
        `X-Request-Id` と同じ値です。
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - request_id
          properties:
            code:
              type: string
              description: エラーを識別するコードです。
              example: CONTACT_EMAIL_CONFLICT
            message:
              type: string
              description: 人が読むための説明です。内容は変わることがあるため、判定には `code` を使ってください。
            request_id:
              type: string
              description: リクエストを識別するIDです。問い合わせの際にお知らせください。
              example: req-1
    V2Actor:
      type: object
      required:
        - kind
        - name
      properties:
        kind:
          type: string
          enum:
            - member
            - api_key
            - ai
            - crm_sync
            - system
        name:
          type: string
    Error:
      type: object
      required:
        - statusCode
        - message
      properties:
        statusCode:
          type: integer
          description: HTTPステータスコード
          example: 404
        message:
          type: string
          description: エラーメッセージ
          example: Meeting not found
        code:
          type: string
          description: >
            エラーを識別するコード。次のエラーでのみ含まれます。

            - `INVALID_API_KEY` (401):
            APIキーが無効・失効・期限切れ、または紐づくアカウントを利用できません。アカウントの状態は区別して返しません。APIキー未指定の
            401 には含まれません

            - `PUBLIC_API_AUTH_CONTEXT_UNAVAILABLE` (502): 認証情報を確認できませんでした

            - `PUBLIC_API_USAGE_RECORD_UNAVAILABLE` (503):
            利用状況を記録できませんでした。再試行できます
          example: INVALID_API_KEY
        error:
          type: string
          description: |
            エラー種別。メッセージ文字列付きで例外が生成された場合のみ含まれます。
          example: Not Found
    V2Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
            request_id:
              type: string
  headers:
    RequestId:
      description: >
        リクエストを識別するIDです。リクエストの `X-Request-Id` ヘッダーがあればその値、なければ Frictio
        が採番した値が返ります。

        エラーの場合は `error.request_id` と同じ値です。
      schema:
        type: string
      example: req-1
  responses:
    V2Unauthorized:
      description: >
        APIキーが無効、失効、期限切れ、または未指定です。

        APIキーの未指定・不一致は `Error` 形式で返します。`INVALID_API_KEY` の `code`
        は本文の一番外側にあり、`message` は理由によって変わります（`Invalid API key` / `API key is
        revoked` / `API key is expired`）。

        認証済みのキーがリクエストの処理時点で利用できなくなっていた場合は、v2 共通の `V2Error` 形式で返します。Contact
        の作成・更新では、サービスアカウントに紐づかない従来の APIキーもこの形式の `401` になります。
      content:
        application/json:
          schema:
            oneOf:
              - $ref: '#/components/schemas/Error'
              - $ref: '#/components/schemas/V2Error'
          examples:
            invalidApiKey:
              summary: 無効な API キー
              value:
                statusCode: 401
                message: Invalid API key
                code: INVALID_API_KEY
            missingApiKey:
              summary: API キー未指定
              value:
                statusCode: 401
                message: Missing X-Api-Key header
                error: Unauthorized
            invalidApiKeyDuringRequest:
              summary: 処理中に API キーを利用できなくなった（失効・期限切れ・無効化など。理由は区別して返しません）
              value:
                error:
                  code: INVALID_API_KEY
                  message: Invalid API key
                  request_id: req-1
    V2ContactWriteForbidden:
      description: |
        APIキーに紐づくサービスアカウントのロールに、この操作に必要な権限がありません。
        - 作成: Contact の作成権限と閲覧権限（ワークスペース全体）が必要です
        - 更新: Contact の編集権限（ワークスペース全体）が必要です
        自分のもの・チームのものだけの範囲の権限では実行できません。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2ContactWriteError'
          example:
            error:
              code: PUBLIC_API_OPERATION_FORBIDDEN
              message: The API key is not permitted to perform this operation
              request_id: req-1
    V2ContactWriteConflict:
      description: >
        メールアドレスは大文字小文字を区別せず、非公開の Contact も競合の対象です。既存の Contact の ID や内容は返しません。


        **作成（POST）**: 同じメールアドレスの有効な Contact がワークスペースにすでに存在する場合に `409` を返します。

        先に送った作成が成功したあとや、エラー・タイムアウトになったものの Contact
        自体は作成されていたあとに再送した場合も、同じ応答になります。

        他の連携や Frictio 上の操作ですでに作成されていた場合もあるため、`409` を自動的に成功として扱わず、結果を確認してください。

        作成後の別の書き込みが失敗した場合は、公開・所有に関する情報や従来の読み取り処理向けの情報が反映されないまま残ることがあります。


        **更新（PATCH）**: メールアドレスの変更先が別の有効な Contact と重複する場合に `409` を返します。

        同じメールアドレスの PATCH を再送したこと自体は、`409` の理由になりません。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2ContactWriteError'
          example:
            error:
              code: CONTACT_EMAIL_CONFLICT
              message: A contact with this email address already exists
              request_id: req-1
    V2ContactWritePayloadTooLarge:
      description: |
        リクエスト本文が大きすぎます（上限は 100 KB）。項目を減らして再試行してください。処理は実行されていません。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2ContactWriteError'
          example:
            error:
              code: PAYLOAD_TOO_LARGE
              message: Request body is too large
              request_id: req-1
    V2ContactWriteUnsupportedMediaType:
      description: >
        リクエスト本文の形式に対応していません。`Content-Type: application/json`（`charset=utf-8`）の
        JSON で送信してください。次の場合に返し、処理は実行されていません。

        - `application/json` 以外の
        `Content-Type`（`application/x-www-form-urlencoded`、`text/plain` など）

        - `Content-Type` を付けていない本文（`Transfer-Encoding: chunked` を含む）

        - 未対応の文字コード（charset）またはエンコーディング
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2ContactWriteError'
          example:
            error:
              code: UNSUPPORTED_MEDIA_TYPE
              message: Request body media type or encoding is not supported
              request_id: req-1
    TooManyRequests:
      description: レートリミット超過
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 429
            message: Too Many Requests
    V2ContactWriteBadGateway:
      description: >
        Frictio側の問題でリクエストを処理できませんでした。

        **作成・更新の結果は不明です。** サーバー側の処理が完了している場合があるため、同じリクエストを自動で再送しないでください。

        - `error.code` が `PUBLIC_API_AUTH_CONTEXT_UNAVAILABLE`:
        認証情報を確認できませんでした。処理は実行されていません。時間をおいて再試行してください

        - `error.code` が `INTERNAL_ERROR`: 内部サービスで障害が発生しました。作成では、Contact
        は作成されているのに一部の項目が反映されていない場合があります。Frictio上で結果を確認してください
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2ContactWriteError'
          examples:
            authContextUnavailable:
              summary: 認証情報を確認できない（処理は実行されていない）
              value:
                error:
                  code: PUBLIC_API_AUTH_CONTEXT_UNAVAILABLE
                  message: Authentication context is unavailable
                  request_id: req-1
            upstreamError:
              summary: 内部サービスの障害（結果は不明）
              value:
                error:
                  code: INTERNAL_ERROR
                  message: Upstream service error
                  request_id: req-1
    V2ContactWriteServiceUnavailable:
      description: >
        一時的にリクエストを処理できません。

        - `error.code` が `CONTACT_WRITE_UNAVAILABLE`: このワークスペースでは Contact
        の書き込みを利用できません。時間をおいて再試行しても解消しません

        - `error.code` が `WORKSPACE_UNDER_MAINTENANCE`:
        ワークスペースがメンテナンス中で書き込みを受け付けていません。時間をおいて再試行してください。作成では、まれに Contact
        が作成済みのことがあり、再試行で `409` が返った場合は結果の確認が必要です

        - `error.code` が `PUBLIC_API_USAGE_RECORD_UNAVAILABLE`:
        APIキーの利用状況を記録できませんでした。時間をおいて再試行してください

        - `error.code` が `INTERNAL_ERROR`: 内部サービスが混雑しています。時間をおいて再試行してください
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2ContactWriteError'
          examples:
            contactWriteUnavailable:
              summary: このワークスペースでは Contact の書き込みを利用できない
              value:
                error:
                  code: CONTACT_WRITE_UNAVAILABLE
                  message: Contact write is not available for this workspace
                  request_id: req-1
            workspaceUnderMaintenance:
              summary: ワークスペースがメンテナンス中
              value:
                error:
                  code: WORKSPACE_UNDER_MAINTENANCE
                  message: The workspace is under maintenance
                  request_id: req-1
    V2ContactWriteGatewayTimeout:
      description: |
        内部サービスの処理が10秒以内に完了しませんでした。
        **作成・更新の結果は不明です。** サーバー側の処理は継続し、完了している場合があります。同じリクエストを自動で再送しないでください。
        作成を再送して `409` が返った場合は、「結果の確認が必要」として扱ってください（成功とは扱わないでください）。
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/V2ContactWriteError'
          example:
            error:
              code: INTERNAL_ERROR
              message: Upstream request timed out
              request_id: req-1
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.