# Geozones API

## getNearestZone

เรียกใช้ภายในจาก SDK ดึงพารามิเตอร์ของ geozone ที่ใกล้ที่สุดและระยะทางไปยัง geozone นั้น นอกจากนี้ยังบันทึกตำแหน่งของอุปกรณ์สำหรับการแจ้งเตือนแบบ geo push

```http
POST https://api.pushwoosh.com/json/1.3/getNearestZone
```


### พารามิเตอร์ของเนื้อหาคำขอ


| พารามิเตอร์ | ประเภท <div style="width:80px"></div> | จำเป็น | คำอธิบาย |
|-----------|--------|:--------:|-------------|
| **application** | `string` | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| **hwid** | `string` | ใช่ | [ID อุปกรณ์ฮาร์ดแวร์](/th/developer/api-reference/api-identifiers/#hardware-id) ที่ใช้ในคำขอ `/registerDevice` |
| **lat** | `string` | ใช่ | ละติจูดของอุปกรณ์ |
| **lng** | `string` | ใช่ | ลองจิจูดของอุปกรณ์ |


### ตัวอย่างคำขอ

```json
{
  "request": {
    "application": "APPLICATION_CODE", 
    "hwid": "HWID",
    "lat": 10.12345,
    "lng": 28.12345
  }
}
```

### ตัวอย่าง PHP

```php
// ดู http://gomoob.github.io/php-pushwoosh/get-nearest-zone.html

use Gomoob\Pushwoosh\Model\Request\GetNearestZoneRequest;

// สร้างอินสแตนซ์ของคำขอ
$request = GetNearestZoneRequest::create()
    ->setHwid('HWID')
    ->setLat(10.12345)
    ->setLng(28.12345);

// เรียกใช้ Web Service '/getNearestZone'
$response = $pushwoosh->getNearestZone($request);

if ($response->isOk()) {
    print 'ชื่อโซน : ' . $response->getResponse()->getName();
    print 'ละติจูด : ' . $response->getResponse()->getLat();
    print 'ลองจิจูด : ' . $response->getResponse()->getLng();
    print 'ระยะ : ' . $response->getResponse()->getRange();
    print 'ระยะทาง : ' . $response->getResponse()->getDistance();
} else {
    print 'อุ๊ปส์ การดำเนินการล้มเหลว :-(';
    print 'รหัสสถานะ : ' . $response->getStatusCode();
    print 'ข้อความสถานะ : ' . $response->getStatusMessage();
}
```


## addGeoZone

เพิ่ม Geozone ไปยังแอปที่ระบุ

```http
POST https://api.pushwoosh.com/json/1.3/addGeoZone
```


### พารามิเตอร์ของเนื้อหาคำขอ


| พารามิเตอร์ <div style="width:150px"></div>  | ประเภท <div style="width:80px"></div> | จำเป็น | คำอธิบาย |
|-----------|--------|:--------:|-------------|
| **auth** | `string` | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) จาก Pushwoosh Control Panel |
| **application** | `string` | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| **geozones** | `array` | ใช่ | พารามิเตอร์ Geozone ในรูปแบบอาร์เรย์ JSON |
| **geozones.name** | `string` | ใช่ | ชื่อ Geozone |
| **geozones.lat** | `string` | ใช่ | ละติจูดของ Geozone |
| **geozones.lng** | `string` | ใช่ | ลองจิจูดของ Geozone |
| **geozones.cooldown** | `integer` | ใช่ | ระยะเวลาเงียบหลังจากการส่งการแจ้งเตือน (เป็นวินาที) |
| **geozones.range** | `integer` | ใช่ | ระยะของ Geozone เป็นเมตร ขั้นต่ำ 50 |
| **geozones.content** | `string or object` | จำเป็นหาก `presetCode` ว่างเปล่า | เนื้อหาข้อความ Geozone |
| **geozones.presetCode** | `string` | จำเป็นหาก `content` ว่างเปล่า | [Push preset](/th/developer/api-reference/api-identifiers/#preset-code) ที่จะใช้แทน `content` |
| **geozones.cluster** | `string` | ไม่ | ระบุ `null` เพื่อยกเลิกการผูกคลัสเตอร์จาก Geozone |
| **geozones.campaign** | `string` | ไม่ | ระบุ `null` เพื่อยกเลิกการผูกแคมเปญจาก Geozone หากไม่ระบุ ค่าแคมเปญจะยังคงไม่เปลี่ยนแปลง หมายเหตุ: มีลำดับความสำคัญสูงกว่าแคมเปญใน preset |
| **geozones.timetable** | `object` | ไม่ | ตั้งค่าช่วงเวลาของตารางเวลา |


### ตัวอย่างคำขอ

```json
{ 
  "request": {
    "auth": "yxoPUlwqm............pIyEX4H",  // โทเค็นการเข้าถึง API จาก Pushwoosh Control Panel
    "application": "XXXXX-XXXXX",            // รหัสแอปพลิเคชัน Pushwoosh
    "geozones": [{
      "name": "Statue of George",            // จำเป็น ชื่อ Geozone
      "lat": "40.70087797",                   // จำเป็น ละติจูดของ Geozone
      "lng": "-73.931851387",                 // จำเป็น ลองจิจูดของ Geozone
      "cooldown": 60,                         // เป็นวินาที จำเป็น ระยะเวลาเงียบหลังจากการส่งการแจ้งเตือน
      "range": 50,                            // เป็นเมตร ขั้นต่ำ 50 จำเป็น ระยะของ geozone
      "content": "Lorem ipsum dolor sit amet,
       consectetur adipiscing elit.",         // หรือ object
      "presetCode": "AAAAA-BBBBB",            // ไม่บังคับ Push preset สามารถใช้แทน content ได้
      "cluster": "GEOZONE CLUSTER CODE",      // ไม่บังคับ ระยะเวลา cooldown ของคลัสเตอร์จะถูกนำมาใช้
      "campaign": "CAMPAIGN_CODE",            // ไม่บังคับ ระบุ null เพื่อยกเลิกการผูก Campaign จาก Geozone
      "timetable": {                          // ไม่บังคับ
        "timezone": 1234,                     // เป็นวินาที
        "Mon": [                              // วันที่ใช้ได้: Mon, Tue, Wed, Thu, Fri, Sat, Sun. การส่ง Push
          {
            "start": "04:11",
            "stop": "12:00"
          }
        ],
        "Sun": [
          {                                    // หนึ่งหรือสองช่วงเวลา
            "start": "01:11",
            "stop": "17:00"
          },
          {
            "start": "18:01",
            "stop": "23:59"
          }
        ]
      }
    }]
  }
}

```
## updateGeoZone

อัปเดตคุณสมบัติของ Geozone

```http
POST https://api.pushwoosh.com/json/1.3/updateGeoZone
```

### พารามิเตอร์ของเนื้อหาคำขอ

| พารามิเตอร์ <div style="width:150px"></div> | ประเภท <div style="width:80px"></div> | จำเป็น | คำอธิบาย |
|-----------|--------|:--------:|-------------|
| **auth** | `string` | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) จาก Pushwoosh Control Panel |
| **geoZoneId** | `string` | ใช่ | [Geozone ID](/th/developer/api-reference/api-identifiers/#geozone-id) จากคำขอ `/addGeoZone` |
| **name** | `string` | ไม่ | ชื่อ Geozone ใหม่ |
| **cooldown** | `integer` | ไม่ | Cooldown ที่จะอัปเดต เป็นวินาที |
| **status** | `integer` | ไม่ | 0 - ปิดใช้งาน, 1 - เปิดใช้งาน |
| **content** | `string` | ไม่ | เนื้อหาสำหรับการแจ้งเตือน push ของ Geozone ไม่สามารถใช้ร่วมกับ `presetCode` ได้ |
| **cluster** | `string` | ไม่ | ชื่อคลัสเตอร์ใหม่ ระบุ `null` เพื่อยกเลิกการผูกคลัสเตอร์จาก Geozone |
| **campaign** | `string` | ไม่ | ID แคมเปญใหม่ ระบุ `null` เพื่อยกเลิกการผูก Campaign จาก Geozone หากไม่ระบุ ค่า Campaign จะไม่เปลี่ยนแปลง มีลำดับความสำคัญสูงกว่า Campaign จาก preset |
| **lat** | `number` | ไม่ | ละติจูดของ Geozone |
| **lng** | `number` | ไม่ | ลองจิจูดของ Geozone |
| **range** | `integer` | ไม่ | ระยะใหม่เป็นเมตร |
| **timetable** | `object` | ไม่ | ตารางเวลาของ Geozone ดูข้อมูลเพิ่มเติมด้านล่าง |

---


### ตัวอย่างคำขอ

```json
{ 
  "request": {
    "auth": "yxoPUlwqm............pIyEX4H",  // จำเป็น, โทเค็นการเข้าถึง API จาก Pushwoosh Control
    "geoZoneId": 100016750,                  // จำเป็น, จากเมธอด /addGeoZone
    "name": "new geozone name",              // ไม่บังคับ
    "cooldown": 222,                         // เป็นวินาที, ไม่บังคับ
    "status": 0,                             // ไม่บังคับ, 0 - ปิดใช้งาน, 1 - เปิดใช้งาน
    "presetCode": "BBBBB-AAAAA",             // ไม่บังคับ, ไม่สามารถใช้ร่วมกับ "content"
    "content": "new geozone content",        // ไม่บังคับ, ไม่สามารถใช้ร่วมกับ "presetCode"
    "cluster": "GEOZONE CLUSTER CODE",       // ไม่บังคับ ระบุ null เพื่อยกเลิกการผูกคลัสเตอร์จาก Geozone
    "campaign": "CAMPAIGN_CODE",             // ไม่บังคับ ระบุ null เพื่อยกเลิกการผูก Campaign จาก Geozone
    "lat": 10.56,                            // ไม่บังคับ, ละติจูดของ geozone
    "lng": 12.523,                           // ไม่บังคับ, ลองจิจูดของ geozone
    "range": 500,                            // ไม่บังคับ, ระยะของ geozone
    "timetable": {                           // ไม่บังคับ
      "timezone": 1234,                      // เป็นวินาที
      "Mon": [                               // วันที่ใช้ได้: Mon, Tue, Wed, Thu, Fri, Sat, Sun. การส่ง Push
        {
          "start": "04:11",
          "stop": "12:00"
        }
      ],
      "Sun": [
        {                                    // หนึ่งหรือสองช่วงเวลา
          "start": "01:11",
          "stop": "17:00"
        },
        {
          "start": "18:01",
          "stop": "23:59"
        }
      ]
    }
  }
}
```

## deleteGeoZone

ลบ Geozones ออกจากแอป

```http
POST https://api.pushwoosh.com/json/1.3/deleteGeoZone
```

### พารามิเตอร์ของเนื้อหาคำขอ


| พารามิเตอร์   <div style="width:150px"></div>   | ประเภท <div style="width:80px"></div>   | จำเป็น | คำอธิบาย |
|-------------|--------|:--------:|-------------|
| **auth**    | `string` | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) จาก Pushwoosh Control Panel |
| **application** | `string` | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| **geozones** | `string` | ใช่ | อาร์เรย์ของ ID หรือ [ID เดียว](/th/developer/api-reference/api-identifiers/#geozone-id) ของ Geozone ที่จะลบ |



### ตัวอย่างคำขอ

```json
{
  "request": {
    "auth": "yxoPUlwqm............pIyEX4H",  // จำเป็น, โทเค็นการเข้าถึง API จาก Pushwoosh Control
    "application": "XXXXX-XXXXX",            // จำเป็น, รหัสแอปพลิเคชัน Pushwoosh
    "geozones": [550, 526]                   // จำเป็น, ID ของ geozones
  }
}
```

## addGeoZoneCluster

เพิ่ม Geozone Cluster ไปยังแอป

```http
POST https://api.pushwoosh.com/json/1.3/addGeoZoneCluster
```


### พารามิเตอร์ของเนื้อหาคำขอ

| พารามิเตอร์  <div style="width:150px"></div>  | ประเภท <div style="width:80px"></div>    | จำเป็น | คำอธิบาย |
|-------------|--------|:--------:|-------------|
| **auth**    | `string` | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) จาก Pushwoosh Control Panel |
| **application** | `string` | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| **name** | `string` | ใช่ | ชื่อคลัสเตอร์ |
| **cooldown** | `integer` | ใช่ | การหน่วงเวลาก่อนที่ผู้ใช้คนเดียวจะสามารถรับข้อความเดียวกันจาก Geozone Cluster ได้ เป็นวินาที |


### ตัวอย่างคำขอ

```json
{
  "request": {
    "auth": "yxoPUlwqm............pIyEX4H",  // จำเป็น, โทเค็นการเข้าถึง API จาก Pushwoosh Control
    "application": "XXXXX-XXXXX",            // จำเป็น, รหัสแอปพลิเคชัน Pushwoosh
    "name": "Raccoon city",                  // จำเป็น, ชื่อคลัสเตอร์
    "cooldown": 3210                         // จำเป็น, เป็นวินาที
  }
}
```

## deleteGeoZoneCluster

ลบ Geozone Cluster ออกจากแอป


```http
POST https://api.pushwoosh.com/json/1.3/deleteGeoZoneCluster
```


### พารามิเตอร์ของเนื้อหาคำขอ


| พารามิเตอร์   <div style="width:150px"></div>        | ประเภท  <div style="width:80px"></div>  | จำเป็น | คำอธิบาย |
|-------------------|--------|:--------:|-------------|
| **auth**         | `string` | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) จาก Pushwoosh Control Panel |
| **application**  | `string` | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |
| **geoZoneCluster** | `string` | ใช่ | ID ของ Geozone cluster ที่จะลบ |


### ตัวอย่างคำขอ

```json
{
  "request": {
    "auth": "yxoPUlwqm............pIyEX4H",  // จำเป็น, โทเค็นการเข้าถึง API จาก Pushwoosh Control
    "application": "XXXXX-XXXXX",            // จำเป็น, รหัสแอปพลิเคชัน Pushwoosh
    "geoZoneCluster": "EA1CE-69405"          // จำเป็น, ID คลัสเตอร์ที่ได้รับจากคำขอ /addGeoZoneCluster
  }
}
```

## listGeoZones

ดึงรายการ Geozones สำหรับแอป


```http
POST https://api.pushwoosh.com/json/1.3/listGeoZones
```

### พารามิเตอร์ของเนื้อหาคำขอ


| พารามิเตอร์  <div style="width:150px"></div>    | ประเภท <div style="width:80px"></div>   | จำเป็น | คำอธิบาย |
|-------------|--------|:--------:|-------------|
| **auth**    | `string` | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) จาก Pushwoosh Control Panel |
| **application** | `string` | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |


### ตัวอย่างคำขอ

```json
{
  "request": {
    "auth": "yxoPUlwqm............pIyEX4H",  // จำเป็น, โทเค็นการเข้าถึง API จาก Pushwoosh Control
    "application": "XXXXX-XXXXX"             // จำเป็น, รหัสแอปพลิเคชัน Pushwoosh
  }
}
```
## listGeoZoneClusters

ดึงรายการ Geozone clusters สำหรับแอป

```http
POST https://api.pushwoosh.com/json/1.3/listGeoZoneClusters
```


### พารามิเตอร์ของเนื้อหาคำขอ


| พารามิเตอร์ <div style="width:150px"></div>   | ประเภท <div style="width:80px"></div>    | จำเป็น | คำอธิบาย |
|-------------|--------|:--------:|-------------|
| **auth**    | `string` | ใช่ | [โทเค็นการเข้าถึง API](/th/developer/api-reference/api-identifiers/#api-access-token) จาก Pushwoosh Control Panel |
| **application** | `string` | ใช่ | [รหัสแอปพลิเคชัน Pushwoosh](/th/developer/api-reference/api-identifiers/#application-code) |


### ตัวอย่างคำขอ

```json
{
  "request": {
    "auth": "yxoPUlwqm............pIyEX4H",  // จำเป็น, โทเค็นการเข้าถึง API จาก Pushwoosh Control
    "application": "XXXXX-XXXXX"             // จำเป็น, รหัสแอปพลิเคชัน Pushwoosh
  }
}
```