# 以用户为中心的 API

## registerUser

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

将外部 User ID 与指定设备关联。

#### 请求头

| 名称 | 必需 | 值 | 描述 |
|---------------|----------|---------------|------------------------------------------------------------|
| Authorization | 是 | Token `XXXX` | 用于访问 Device API 的 [API Device Token](/zh/developer/api-reference/api-access-token/#device-api-token)。请将 `XXXX` 替换为您的实际 Device API token。 |

#### 请求体

| 名称 | 必需 | 类型 | 描述 |
| ----------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| userId | 否 | string | 要与设备关联的 [User ID](/zh/developer/api-reference/api-identifiers/#user-id)。如果为空，则使用 hwid。 |
| application | 是 | string | [Pushwoosh application code](/zh/developer/api-reference/api-identifiers/#application-code) |
| hwid | 是 | string | [Pushwoosh HWID](/zh/developer/api-reference/api-identifiers/#hardware-id) |
| tz_offset | 否 | integer | 设备的秒级时区偏移量。 |
| device_type | 否 | integer | [设备类型](/zh/developer/api-reference/api-identifiers/#device-type)。请参阅 `/registerDevice` 中的可能值。 |

稍后可在 [`/createMessage`](/zh/developer/api-reference/messages-api/#createmessage) API 调用（_users_ 参数）中使用。\
您可以在拥有 push token 之前以及在调用 [`/registerDevice`](/zh/developer/api-reference/device-api/#registerdevice) 之前调用此函数。

#### 请求示例

```json
{
  "request": {
    "userId": "user_3078a",                     // optional. If empty, use hwid
    "application": "XXXXX-XXXXX",               // required. Pushwoosh application code
    "hwid": "8f65b16df378e7a6bece9614e1530fb2", // required. Hardware device ID
    "tz_offset": -3600,                         // optional. Timezone offset in seconds
    "device_type": 3                            // optional. Device type, see /registerDevice
                                                //           for device types
  }
}
```

#### 响应示例

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

<Aside type="note">
对于电子邮件，请调用 [`/registerEmailUser`](/zh/developer/api-reference/email-api/#registeremailuser)。
</Aside>

## deleteUser

`POST` `https://api.pushwoosh.com/api/v2/device-api/deleteUser`

删除用户以及与应用程序内指定的 [User ID](/zh/developer/api-reference/api-identifiers/#user-id) 关联的所有设备。该请求是异步处理的，一旦删除请求被接受处理，端点就会返回 `200 OK`。

#### 请求头

| 名称 | 必需 | 值 | 描述 |
|---------------|----------|------------------|------------------------------------------------------------|
| Authorization | 是 | Token `XXXX` | 用于访问 Device API 的 [API Device Token](/zh/developer/api-reference/api-access-token/#device-api-token)。请将 `XXXX` 替换为您的实际 Device API token。 |
| Content-Type | 是 | application/json | |

#### 请求体

| 名称 | 必需 | 类型 | 描述 |
| ----------- | -------- | ------ | --------------------------------------------------------------------------------------------------------------- |
| application | 是 | string | [Pushwoosh application code](/zh/developer/api-reference/api-identifiers/#application-code) |
| user_id | 是 | string | 要删除的 [User ID](/zh/developer/api-reference/api-identifiers/#user-id)。与此用户在指定应用程序中关联的所有设备都将被移除。 |


#### 请求示例

```json
{
  "application": "XXXXX-XXXXX",   // required. Pushwoosh application code
  "user_id": "user_3078a"         // required. User ID to delete
}
```

#### 响应示例

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

##### 状态码

| HTTP 状态码 | status_code | 描述 |
| ---------------- | ------------ | -------------------------------------------------- |
| 200 | 200 | 删除请求已接受 |
| 200 | 210 | 参数错误。请参阅 status_message 了解更多信息。 |
| 400 | N/A | 请求字符串格式错误 |
| 401 | N/A | 缺少或无效的 Authorization token |
| 500 | 500 | 内部错误 |

## postEvent

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

触发一个事件。

#### 请求头

| 名称 | 必需 | 值 | 描述 |
|---------------|----------|---------------|------------------------------------------------------------|
| Authorization | 是 | Token `XXXX` | 用于访问 Device API 的 [API Device Token](/zh/developer/api-reference/api-access-token/#device-api-token)。请将 `XXXX` 替换为您的实际 Device API token。 |


#### 请求体

| 名称 | 必需 | 类型 | 描述 |
| ---------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| hwid | 是 | string | 在 /registerDevice 请求中使用的 [Hardware device ID](/zh/developer/api-reference/api-identifiers/#hardware-id)。可与 'userId' 一起使用，以识别触发事件的用户。 |
| application | 是 | string | [Pushwoosh application code](/zh/developer/api-reference/api-identifiers/#application-code) |
| event | 是 | string | [事件名称](/zh/developer/api-reference/api-identifiers/#event-name)，与在 Pushwoosh Control Panel 中创建的完全一致。 |
| attributes | 是 | object | 包含事件属性的 JSON 对象。如果不需要传递任何属性，请将其留空。 |
| timestampUTC | 否 | integer | UTC 时间戳。 |
| timestampCurrent | 否 | integer | 本地时间的时间戳。 |
| userId | 是 | string | 与触发事件的用户关联的 [User ID](/zh/developer/api-reference/api-identifiers/#user-id)。可以替换或与 HWID 一起使用。 |
| device_type | 否 | integer | [查看可能的值](/zh/developer/api-reference/api-identifiers/#device-type) |

请求中的事件名称必须与 Pushwoosh Control Panel 中的事件名称匹配。请注意，如果事件没有属性，"attributes" 属性可以为空（但不能省略）。

#### 请求示例

```json
{
  "request":{ 
    "hwid": "8f65b16df378e7a6bece9614e1530fb2", // required. Hardware device ID used in a /registerDevice API.
                                                //           Can be used along with an userId to identify a 
                                                //           user who has triggered an event.
    "application": "XXXXX-XXXXX",               // required. Pushwoosh application code
    "event": "activityCompleted",               // required. Event name exactly as created in Pushwoosh Control Panel
    "attributes": {                             // required. Leave empty if no attributes need to be passed. 
      "login": "facebook",
      "success": "yes",
      "internet": "wifi"
    },
    "timestampUTC": 1435228403,                 // optional. Timestamp in UTC
    "timestampCurrent": 1435253603,             // optional. Timestamp in local time
    "userId": "someuser@user.com",              // required. A user id which is used for identification of 
                                                //           users on multiple devices. Can be replaced by
                                                //           or used along with an HWID.
    "device_type": 1                            // optional.
  }
}

```

#### 响应示例

<Tabs>
<TabItem label="200">
```json
{
  "status_code": 200,
  "status_message": "OK",
  "response": {
    "code": "61BC9-84DD0"
  }
}
```
</TabItem>
</Tabs>