# Presets API

## createPreset

`POST` `https://api.pushwoosh.com/json/1.3/createPreset`

创建一个新的预设。

#### Request Body

| 名称 | 类型 | 描述 |
| --- | --- | --- |
| auth\* | string | 来自 Pushwoosh 控制面板的 [API Access Token](/zh/developer/api-reference/api-identifiers/#api-access-token)。 |
| name\* | string | 预设名称。 |
| applicationCode\* | string | [Pushwoosh Application Code](/zh/developer/api-reference/api-identifiers/#application-code) |
| campaignCode | string | 您想要分配此预设的 [Campaign Code](/zh/developer/api-reference/api-identifiers/#campaign-code)。 |
| content\* | object | 消息内容参数。 |
| content.message\* | string | 字符串或数组。消息内容。如果是字符串，将使用 "Default"（默认）语言。 |
| content.action | object | 自定义动作参数。见下例。 |
| content.userData | array | 自定义用户数据。将作为 payload 中的 "u" 参数传递（转换为 JSON 字符串）。 |
| content.properties | array | 不同平台的特定内容。见下例。 |
| scheduling.sendRate | integer | 限流。有效值为 100 到 1000 pushes/second。 |
| segmentation | object | 细分参数 |
| segmentation.filter | string | [Segment (filter) 名称](/zh/developer/api-reference/api-identifiers/#segment--filter-name) |
| segmentation.platforms\* | array | 整数数组。平台 ID 列表。1 - iOS, 3 - Android, 7 - Mac OS X, 8 - Windows, 9 - Amazon, 10 - Safari, 11 - Chrome, 12 - Firefox。 |

<Tabs>
<TabItem label="200">
```json
{
  "status_code": 200,
  "status_message": "OK"
}
```
</TabItem>
</Tabs>

```jsonc title="Example"
{
  "request": {
    "auth": "yxoPUlwqm…………pIyEX4H",        // 必填。来自 Pushwoosh 控制面板的 API Access Token。
    "name": "PRESET_NAME",                 // 必填。
    "applicationCode": "XXXXX-XXXXX",      // 必填。Pushwoosh Application Code。
    "applicationGroupCode": "AAAAA-BBBBB", // 可选。可用于替代 "applicationCode"。
    "campaignCode": "CCCCC-DDDDD",         // 可选。Campaign Code。
    "content": {                           // 必填。包含消息数据。
      "message": {                         // 必填。字符串或对象。消息内容。如果是
        "en": "English message",           //           字符串，将使用默认语言。
        "fr": "French message"             //           针对不同语言本地化的消息内容。
      },                                   //           仅支持 ISO 639-1:2002 语言代码。
      "title": {                           // 可选。字符串或对象。对于多语言，设置
        "en": "English title",             //           对象中每种语言的标题。如果指定了
        "fr": "French title"               //           平台特定标题（例如，
      },                                   //           'ios_title', 'android_header' 等；参见
                                           //           /createMessage API 中的平台特定
                                           //           参数示例），则忽略此项。
      "subtitle": {                        // 可选。字符串或对象。对于多语言，设置
        "en": "English subtitle",          //           对象中每种语言的标题。如果指定了
        "fr": "French subtitle"            //           平台特定副标题（例如，
      },                                   //           'ios_subtitle' 等；参见 /createMessage API
                                           //           中的平台特定参数示例），则忽略此项。
      "action": {                          // 可选。用户打开消息后执行的动作。
        "type": "url",                     // 可选。动作类型。可用类型："url", "deepLink",
                                           //            "richMedia", "openApp"（默认）。
        "options": {                       // 可选。动作类型的选项。除 "openApp" 外的所有
                                           //           动作类型均为必填。
          "url": "https://example.com",    // "url" 动作类型必填，字符串。如果定义了短链接生成器
                                           //           将被缩短。
          "shortener": 2,                  // 可选。可用值：0 - 不缩短，2 - bit.ly。
                                           //           如果未指定短链接生成器，默认使用 bit.ly
                                           //           短链接生成器。
          "richMediaCode": "BBBBB-AAAAA",  // "richMedia" 动作类型必填，字符串。
                                           //           来自 Pushwoosh 控制面板的 Rich Media code。
          "id": 123,                       // "deepLink" 动作类型必填，整数。Deep Link ID。
          "params": {                      // 可选，自定义参数，"deepLink" 动作类型必填，数组。
            "param1": "value1",
            "param2": "value2"
          }
        }
      },
      "userData": {                        // 可选。自定义用户数据。将作为 "u"
        "CustomData": "value"              //           参数在 payload 中传递（转换为 JSON 字符串）。
      },
      "platforms": {
        "ios": {
          "sound": "default",
          "silent": 1,
          "ttl": 604800,
          "rootParams": {
            "rule_id": "12345",
            "screen_id": "34567"
          },
          "interruptionLevel": "active"
        },
        "android": {
          "rootParams": {
            "rule_id": "12345",
            "screen_id": "34567"
          }
        }
      }
    },
    "scheduling": {            // 可选。调度选项。
      "sendRate": 1000         // 可选。限流。有效值为 100 到 1000 pushes/second。
    },
    "segmentation": {          // 必填。细分选项。
      "filter": "FILTER NAME", // 可选。来自 Pushwoosh 控制面板的 Filter name。
      "platforms": [1, 3]      // 必填。平台 ID 列表：1 — iOS; 3 — Android;
                               //           7 — Mac OS X; 8 — Windows; 9 — Amazon; 10 — Safari;
                               //           11 — Chrome; 12 — Firefox;
    }
  }
}
```

<Aside type="note">
有关平台特定参数，请参阅 [`/createMessage`](/zh/developer/api-reference/messages-api/#createmessage)。
</Aside>

## getPreset

`POST` `https://api.pushwoosh.com/json/1.3/getPreset`

检索特定推送预设的参数。

#### Request Body

| 名称 | 类型 | 描述 |
| --- | --- | --- |
| auth\* | string | 来自 Pushwoosh 控制面板的 [API Access Token](/zh/developer/api-reference/api-identifiers/#api-access-token)。 |
| preset\_code\* | string | 要检索信息的 Push [Preset Code](/zh/developer/api-reference/api-identifiers/#preset-code)。 |

<Tabs>
<TabItem label="200">
```json
{ 
  "status_code": 200,
  "status_message": "OK",
  "response": { 
    "preset": { 
      "code": "XXXXX-XXXXX",
      "name": "Full preset",
      "page_id": 26,
      "url": null,
      "content": { 
        "en": "Some message",
        "de": "Eine Nachricht"
      },
      "properties": { 
        "ignore_user_timezone": 1,
        "ios_badges": "5",
        "ios_sound": "default",
        "ios_ttl": "43200",
        "android_sound": "Sound1.wav",
        "android_custom_icon": "icon.png",
        "android_header": "android_header",
        "android_gcm_ttl": "43200",
        "wns_type": "toast",
        "wns_content": { 
          "template": "ToastImageAndText02",
          "lang-en": { 
            "headlinetext": "Title",
            "bodytext": "super text"
          },
          "languages": ["en", "zh", "it", "sv", "de", "fr", "pt", "nl", "es"],
          "lang-zh": { 
            "headlinetext": "",
            "bodytext": ""
          },
          "lang-it": { 
            "headlinetext": "",
            "bodytext": ""
          },
          "lang-sv": { 
            "headlinetext": "",
            "bodytext": ""
          },
          "lang-de": { 
            "headlinetext": "",
            "bodytext": ""
          },
          "lang-fr": { 
            "headlinetext": "",
            "bodytext": ""
          },
          "lang-pt": { 
            "headlinetext": "",
            "bodytext": ""
          },
          "lang-nl": { 
            "headlinetext": "",
            "bodytext": ""
          },
          "lang-es": { 
            "headlinetext": "",
            "bodytext": ""
          },
          "imagesource": "https:\/\/image.com\/jpg"
        },
        "adm_sound": "song",
        "adm_custom_icon": "i5.bmp",
        "adm_header": "Amazon Header",
        "adm_ttl": "7200",
        "safari_title": "Safari title",
        "safari_action": "OK",
        "safari_url_args": ["hello.com", ""],
        "safari_ttl": "43200",
        "userdata": "{\"custom\":\"data\"}",
        "created_via": "CP",
        "user_id": 2,
        "filter_id": "1"
      },
      "platforms": [1, 3, 7, 10, 11]
    }
  }
}
```
</TabItem>
</Tabs>

```jsonc title="Example"
{
  "request":{
    "auth": "yxoPUlwqm…………pIyEX4H", // 必填。来自 Pushwoosh 控制面板的 API Access Token
    "preset_code": "AAAAA-BBBBB"    // 必填。要检索信息的 Push Preset Code
  }
}
```

## listPresets

`POST` `https://api.pushwoosh.com/json/1.3/listPresets`

检索为该应用创建的预设列表。

#### Request Body

| 名称 | 类型 | 描述 |
| --- | --- | --- |
| auth\* | string | 来自 Pushwoosh 控制面板的 [API Access Token](/zh/developer/api-reference/api-identifiers/#api-access-token)。 |
| application\* | string | [Pushwoosh Application Code](/zh/developer/api-reference/api-identifiers/#application-code) |

<Tabs>
<TabItem label="No presets">
```json
{
  "status_code": 200, 
  "status_message": "OK", 
  "response": {
    "presets": []
  }
}
```
</TabItem>

<TabItem label="Presets list">
```json
{
  "status_code": 200, 
  "status_message": "OK", 
  "response": {
    "presets": [{
      "name": "test",
      "code": "AAAAA-BBBBB"
    }]
  }
}
```
</TabItem>
</Tabs>

```jsonc
{
  "request": {
    "auth": "yxoPUlwqm…………pIyEX4H",  // 必填。来自 Pushwoosh 控制面板的 API Access Token
    "application": "XXXXX-XXXXX"     // 必填。Pushwoosh Application Code
  }
}
```

## deletePreset

`POST` `https://api.pushwoosh.com/json/1.3/deletePreset`

从您的帐户中删除预设。

#### Request Body

| 名称 | 类型 | 描述 |
| --- | --- | --- |
| auth\* | string | 来自 Pushwoosh 控制面板的 [API Access Token](/zh/developer/api-reference/api-identifiers/#api-access-token)。 |
| preset\_code\* | string | 从 Pushwoosh 控制面板或 `/listPresets` API 响应中检索到的 [Preset Code](/zh/developer/api-reference/api-identifiers/#preset-code)。 |

<Tabs>
<TabItem label="200">
```json
{
  "status_code": 200,
  "status_message": "OK",
  "response": null
}
```
</TabItem>
</Tabs>

```jsonc title="Example"
{
  "request": {
    "auth": "yxoPUlwqm…………pIyEX4H", // 必填。来自 Pushwoosh 控制面板的 API Access Token
    "preset_code": "AAAAA-BBBBB"    // 必填。要删除的 Preset Code
  } 
}
```