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

# Insert/Update Treatment Type

> APIs for inserting and updating treatments via API.

<Note>
  日本語版はAIによる翻訳です。正確な情報については[英語版](/api-reference/treatment-management/insert-update-treatment-type)をご参照ください。
</Note>

このドキュメントでは、APIを通じてトリートメントタイプの挿入と更新を行えるInsertTreatmentTypeおよびUpdateTreatmentType RPCのガイドと概要を提供します。

## API定義

```url theme={null}
POST https://apis.auxia.io/v1/InsertTreatmentType
```

```url theme={null}
POST https://apis.auxia.io/v1/UpdateTreatmentType
```

## エンティティ

### SurfacePb

```
message SurfacePb {
  string surface_name = 1;
}
```

<Note>
  ここで指定するSurfaceは、あらかじめそのプロジェクトに存在している必要があります。存在しない場合、リクエストは`400`で拒否されます。事前に[Insert Surface](/ja/api-reference/treatment-management/insert-surface)でSurfaceを登録してください。
</Note>

### TreatmentContentFieldTypePb

```
enum ContentFieldDataType {
  CONTENT_FIELD_DATA_TYPE_UNSPECIFIED = 0;
  STRING = 1;
  HTML = 2;
}
message TreatmentContentFieldTypePb {
  // Required
  string field_name = 1;

  // Required
  // Maximum Length allowed for the field
  int32 maximum_length_allowed = 2;

  // Optional
  // Set it to true if multiple language support is required.
  // By default it will be set to false.
  bool is_per_language = 3;

  // Required
  // By default it will be set to STRING
  ContentFieldDataType data_type = 4;
}
```

### TreatmentTypePb

```
message TreatmentTypePb {
int64 treatment_type_id = 1;
string project_id = 2;
string treatment_type_name = 3;
repeated TreatmentContentFieldTypePb content_field_types = 4;
repeated SurfacePb surfaces = 5;
}
```

## InsertTreatmentType

### トリートメントタイプを挿入するAPI

```
message InsertTreatmentTypeRequest {
  // Required
  string project_id = 1;

  // Required
  string treatment_type_name = 2;

  // Required
  repeated SurfacePb surfaces = 3;

  // Required
  repeated TreatmentContentFieldTypePb content_field_types = 4;

  // Required
  string last_modified_by = 5;
}
message InsertTreatmentTypeResponse {
  TreatmentTypePb treatment_type = 1;
}

```

### サンプルcURLリクエスト

```
curl --location --request POST 'https://apis.auxia.io/v1/InsertTreatmentType' \
--header 'Content-Type: application/json' \
--header 'x-api-key: TEST_API_KEY' \
--data-raw '{
  "project_id": "PROJECT_ID",
  "treatment_type_name": "TREATMENT_TYPE",
  "last_modified_by": "USER_EMAIL",
  "surfaces": [
    {
      "surface_name": "IN_APP_CONTENT"
    }
  ],
  "content_field_types": [
     {
       "field_name": "title",
       "maximum_length_allowed": 20
     },
     {
       "field_name": "body",
       "maximum_length_allowed": 100
     }
  ]
}'
```

### サンプルレスポンス

```
{
  "treatmentType": {
    "treatmentTypeId": "TREATMENT_TYPE_ID",
    "projectId": "PROJECT_ID",
    "treatmentTypeName": "TREATMENT_TYPE",
    "contentFieldTypes": [
      {
        "fieldName": "title",
        "maximumLengthAllowed": 20,
        "dataType": "STRING"
      },
      {
        "fieldName": "body",
        "maximumLengthAllowed": 100,
        "dataType": "STRING"
      }
    ],
    "surfaces": [
      {
        "surfaceName": "IN_APP_CONTENT"
      }
    ]
  }
 }
```

## UpdateTreatmentType

### トリートメントタイプを更新するAPI

```
message UpdateTreatmentTypeRequest {
  // Required
  string project_id = 1;

  // Required
  int64 treatment_type_id = 2;

  // Optional
  // If the field is not set, treatment_type_name will not be changed.
  // Empty treatment_type_name is not allowed.
  optional string treatment_type_name = 3;

  // Optional
  // If the field is not set, surfaces will not be changed. An empty list on its own also means
  // "not changed", because a repeated field cannot distinguish unset from empty. To detach every
  // surface, send an empty list together with clear_surfaces = true.
  SurfacePb surfaces = 4;

  // Required
  TreatmentContentFieldTypePb content_field_types = 5;

  // Required
  string last_modified_by = 6;

  // Optional
  // Set to true, with surfaces empty, to detach every surface from the treatment type. A treatment
  // type with zero surfaces is a valid state. Setting this to true with a non-empty surfaces list is
  // rejected.
  optional bool clear_surfaces = 7;
}
message UpdateTreatmentTypeResponse {
  TreatmentTypePb treatment_type = 1;
}

```

### サンプルcURLリクエスト

```
curl --location --request POST 'https://apis.auxia.io/v1/UpdateTreatmentType' \
--header 'Content-Type: application/json' \
--header 'x-api-key: TEST_API_KEY' \
--data-raw '{
  "project_id": "PROJECT_ID",
  "treatment_type_name": "TREATMENT_TO_BE_INSERTED",
  "treatment_type_id": "TREATMENT_TYPE_ID",
  "last_modified_by": "USER_EMAIL",
  "surfaces": [
    {
      "surface_name": "IN_APP_CONTENT"
    }
  ],
  "content_field_types": [
     {
       "field_name": "title",
       "maximum_length_allowed": 20
     },
     {
       "field_name": "body",
  	   "maximum_length_allowed": 100
     },
     {
       "field_name": "cta_url",
       "maximum_length_allowed": 50
     }
  ]
}'
```

### サンプルcURLリクエスト: すべてのサーフェスを解除する

`surfaces`を指定せず、`clearSurfaces`を`true`に設定します。`clearSurfaces`を指定せずに`surfaces`を省略した場合、既存のサーフェスはそのまま維持されます。

```
curl --location --request POST 'https://apis.auxia.io/v1/UpdateTreatmentType' \
--header 'Content-Type: application/json' \
--header 'x-api-key: TEST_API_KEY' \
--data-raw '{
  "projectId": "PROJECT_ID",
  "treatmentTypeId": "TREATMENT_TYPE_ID",
  "lastModifiedBy": "USER_EMAIL",
  "clearSurfaces": true,
  "contentFieldTypes": [
     {
       "fieldName": "title",
       "maximumLengthAllowed": 20
     }
  ]
}'
```

### サンプルレスポンス

```
{
  "treatmentType": {
    "treatmentTypeId": "TREATMENT_TYPE_ID",
    "projectId": "PROJECT_ID",
    "treatmentTypeName": "TREATMENT_TO_BE_INSERTED",
    "contentFieldTypes": [
      {
        "fieldName":"title",
        "maximumLengthAllowed":20,
        "dataType":"STRING"
      },
      {
        "fieldName":"body",
        "maximumLengthAllowed":100,
        "dataType":"STRING"
      },
      {
        "field_name": "cta_url",
        "maximum_length_allowed": 50
      }
    ],
    "surfaces": [
      {
        "surfaceName": "IN_APP_CONTENT"
      }
    ]
  }
 }
```
