# Introduction

MapaKalamidad.ph is a project initiated by Yayasan Peta Bencana as a free, transparent platform for emergency response and disaster management.

The platform adopts a “people as sensors” paradigm, where confirmed reports are collected directly from the users at street level in a manner that removes expensive and time-consuming data processing. This framework creates accurate, real-time data which is immediately made available for users and first responders.\
\
MapaKalamidad.ph gathers, sorts, and visualizes data using specially developed Situational Intelligence Open Source Software (Siti OSS) - an enterprise-level platform for emergency response and disaster management - to transforms the noise of social and digital media into critical information for residents, communities, and government agencies

## MapaKalamidad Data API

MapaKalamidad is backed by a data [API](https://en.wikipedia.org/wiki/Application_programming_interface) exposing a number of public and private endpoints. The documentation that follows allows developers to get up and running. The project is fully open source and the code is available in the [MapaKalamidad GitHub](https://github.com/petabencana/). The architectural diagram is available in different formats:

* [PDF](https://github.com/petabencana/petabencana-docs/tree/d8b3cac5b3bc2a65abd49d874bf9c5798e93eb97/petabencana.pdf)
* [Visio XML](https://github.com/petabencana/petabencana-docs/tree/d8b3cac5b3bc2a65abd49d874bf9c5798e93eb97/petabencana.vdx)
* [OmniGraffle](https://github.com/petabencana/petabencana-docs/tree/d8b3cac5b3bc2a65abd49d874bf9c5798e93eb97/petabencana.graffle.zip)

### Our Sponsors

#### Funding partners

![USAid](https://3179361472-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2Fb3ad4cb1b29087495f3d78ee490657c362e5ea4a.png?generation=1613027636895043\&alt=media)

#### Data Partners

![](https://3179361472-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2F12a2fc18eac7ea65dc4ebcde50fc28b64f0e1275.png?generation=1613027638254141\&alt=media)

![](https://3179361472-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2F-MTien38ZQUgrRi2vNRe%2F-MTif7N23cXslPXiqaqr%2Fimage.png?alt=media\&token=5d4b92a5-7596-4f0e-9984-a0f73c407fbb)

#### Implementing Partners

![](https://3179361472-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2F-MTien38ZQUgrRi2vNRe%2F-MTifGsQSC1dgPmVV4Jv%2Fimage.png?alt=media\&token=39af78a2-3ea3-4d46-9027-aa5d18c664dc)

![](https://lh3.googleusercontent.com/H8gW0VyDUa1S7ZwRQ2e59qG4Tnmb7Qo59UTzDWxQIm1jc1Z2hnOyPXz-7rqPczyDfaIKEed0fWF58wtbIrpjSDVGJ_ytglkXR4rP2dLz5l7apLAgDe0Th9USpdMBbVpcyx86Pi2Q)

![](https://lh5.googleusercontent.com/39INbdeXc4iSWDnr7r_fKZcPMUIlJagm8i_jQx_XtQYuKJaeiEuEq6xTrJBYjHtOErLTSrvciNTWwsZRNvLgk94MJU4Rc40j2m71Vmg3KUwRLDpKLH169DDW9AEY5nfW9HcYuFnE)

![](https://lh6.googleusercontent.com/kDOIoRA9eQfqalhssYke4GdD2pfPbVBECUU6tmL8s22n8UgUiX7x7uLiRPZ_7PFfPxStA6jOIeAjnkYczzIP-h0g5pJWeygHRSvKsnR4Zgl2riSFyaU05HJoB9t1FdMdfvRoUB5r)

#### Project Partners

![](https://3179361472-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2Fd4cb04c472cdcfce42d27d63c8a4c30f19ee5acb.png?generation=1613027636486005\&alt=media) ![](https://3179361472-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2F9e00a7b592319e9d532c55cc6d332c4fdc3f4f09.png?generation=1613027638037008\&alt=media) ![](https://3179361472-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2Fc8146ddac882b1f1aa93900e32942896891fded9.png?generation=1613027636694275\&alt=media)


# General

There are a number of general standards which apply regardless of the API being called and these are documented in the pages that follow.


# Authentication

The MapaKalamidad API exposes some protected routes which will require authentication to access. Authentication is via a [JSON Web Token](https://jwt.io/introduction/)

Note: For a new API key, please reach out to MapaKalamidad team


# Versioning

The API is versioned with a version string specified in the base URL that can be incremented independently from other APIs.

Using the newest available API is always encouraged.

These changes are considered backwards compatible and will not require the version string to be incremented:

* Adding properties to JSON objects
* Adding new parameters
* Changing the number of items returned in a single listing request
* The structure or length of identifiers generated by the API
* Changing error messages

These changes are considered backwards incompatible and will require the version string to be incremented:

* Removing properties from JSON objects
* Changing an API's URL structure

The current version is v1


# Rate Limits

The MapaKalamidad API employs rate limiting that cap the number of requests that can be made against an endpoint. If you exceed a rate limit, your request will be throttled and you will receive `HTTP 429 Too Many Requests responses from the API.`

You are encouraged to always stay within your allocated quota and implement retries in your code where applicable.


# CORS

[Cross-Origin Requests](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) are supported with no domain restrictions to allow for ease of integration into browser based applications.


# HTTPS

Access to all APIs over HTTPS is mandatory. Requests initiated over HTTP are automatically upgraded to HTTPS.


# Coordinates

The default spatial reference system used is [WGS84](https://en.wikipedia.org/wiki/World_Geodetic_System).


# Error Codes

MapaKalamidad uses the standard [HTTP Status Codes](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) to communicate errors together with a json formatted error message giving more information as to the root cause of the error. The main codes used are as follows:

## 4xx Errors

Errors starting with a 4 generally indicate a client side issue that must be resolved before re-querying the service such as:

* **400 Bad Request** - normally caused by an incorrect query parameter e.g. `"child \"type\" fails because [\"type\" must be one of [floodgates, pumps, waterways]]"`
* **403 Forbidden** - the authentication token is invalid
* **404 Not Found** - the resource was not found, this may indicate an incorrect endpoint or trying to retrieve a record for example, a report, which does not exist
* **409 Conflict** - the resource exists but if the request was allowed a conflict would be created in the system, for example, filing a report for a card where a report already exists
* **415 Unsupported Media Type** - the file being uploaded is not supported by the system - this usually means a binary file such as an image is being uploaded but the Content-Type header with the associated MIME type (e.g. \`image/jpeg\`) has not been supplied
* **429 Too Many Requests** - you have exceeded your per second or per day quota of requests

## 5xx Errors

Errors starting with a 5 generally indicate a server side fault and should be immediately:

* **500 Internal Server Error** - a catch-all error indicating that something has failed server side
* **503 Service Unavailable** - the service is down and cannot respond to requests


# Content Types

By default the MapaKalamidad API returns [JSON](http://www.w3schools.com/json/) for all calls and expects any POST requests to supply JSON formatted bodies unless otherwise advised. [UTF-8 encoding](https://en.wikipedia.org/wiki/UTF-8) is used on all requests and responses.

Where Geographic data is returned this is will be encoded as [TopoJSON](https://github.com/topojson/topojson/wiki) by default. [GeoJson](http://geojson.org/) is also supported if required, by supplying `format=topojson in the API call. More details of this can be found in the specific API route documentation. In addition to TopoJSON and GeoJson we provide a public feed of real-time flood information using the`[`Common Alerting Protocol`](https://en.wikipedia.org/wiki/Common_Alerting_Protocol)`standard.`


# Examples

The APIs all feature worked examples with sample HTTPS calls. As we need to pass authentication headers in some cases to be able to connect we cannot run these in a web browser. Each example shows a [cURL](https://curl.haxx.se/docs/manpage.html) command which is available on Windows, Mac or Linux. Note that for protected routes you will need to insert your own JWT token for these to work.

If you are not comfortable with the command line or generally prefer a user interface then [Postman](https://www.getpostman.com/) is a fantastic free tool for experimenting with APIs.


# Supported Area

Mapakalamidad.ph is active and can be utilized in all regions in the Philippines. Regional codes are required on some feeds. The following is a list of codes for each region:

<table><thead><tr><th width="379">Region</th><th>Code</th></tr></thead><tbody><tr><td>National Capital Region</td><td>PH-00</td></tr><tr><td>Ilocos Region</td><td>PH-01</td></tr><tr><td>Cagayan Valley</td><td>PH-02</td></tr><tr><td>Central Luzon</td><td>PH-03</td></tr><tr><td>CALABARZON</td><td>PH-40</td></tr><tr><td>MIMAROPA</td><td>PH-41</td></tr><tr><td>Bicol Region</td><td>PH-05</td></tr><tr><td>Western Visayas</td><td>PH-06</td></tr><tr><td>Central Visayas</td><td>PH-07</td></tr><tr><td>Eastern Visayas</td><td>PH-08</td></tr><tr><td>Zamboanga Peninsula</td><td>PH-09</td></tr><tr><td>Northern Mindanao</td><td>PH-10</td></tr><tr><td>Davao Region</td><td>PH-11</td></tr><tr><td>SOCCSKSARGEN</td><td>PH-12</td></tr><tr><td>Caraga Region</td><td>PH-13</td></tr><tr><td>Bangsamoro Autonomous Region of Muslim Mindanao</td><td>PH-14</td></tr><tr><td>Cordillera Administrative Region</td><td>PH-15</td></tr></tbody></table>


# Supported Hazards

Mapakalamidad.ph currently supports 4 types of disasters, as follow:

1. Flood
2. Typhoon
3. Earthquake
4. Volcano

For the scope of this documentation, the disasters will have the following information:

| Disaster Type | report\_type | Attribute details                                                                                                                                                                                                                                                                                                                                                                           |
| ------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Flood         | flood        | <p><strong>flood\_depth:</strong> flood severity based on depth in cm<br></p><p>< 70 cm : Minor</p><p>70 - 150 cm : Moderate</p><p>150 cm : Severe</p>                                                                                                                                                                                                                                      |
| Typhoon       | wind         | <p>impact: level of disruption caused by extreme wind<br>powerOutRage: Are you experiencing a power outage?</p><p><br>0 : Low Disruption <br>1 : Medium Disruption <br>2 : High Disruption</p>                                                                                                                                                                                              |
| Typhoon       | storm        | <p>impact: level of disruption caused by extreme wind<br><br>powerOutRage: Are you experiencing a power outage?<br><br>0 : Low Disruption <br>1 : Medium Disruption <br>2 : High Disruption<br></p>                                                                                                                                                                                         |
| Earthquake    | road         | <p>accessabilityFailure: the level of road damage affected by earthquake<br>condition: level of disturbance caused<br></p><p>0 : < 0,5 m (No Vehicle Access) <br>1 : 0,6 - 1 m (2 or 3-Wheel Vehicle Access) <br>2 or 3 : 1.1 - 1.8 m (4-Wheel Vehicle Access) <br>4 : >1,9 m (Large Vehicle Access)<br><br>0 : Low Disturbance <br>1 : Medium Disturbance <br>2 : High Disturbance<br></p> |
| Volcano       | volcanic     | <p>volcanicSigns: described by symptoms felt by humans<br></p><p>0 : Water Sources are drying up/Contaminated,</p><p>1: Unusual Animal Behaviour,</p><p>3: Frequent Earthquake Tremors,</p><p>4: Frequent Rumbling Sounds</p>                                                                                                                                                               |
| Volcano       | smog         | <p>smogRadius: the radius of a smog estimated by the human eye<br>smogImpact: Impact of ashfall or smog<br><br>0: Fine/Dry (difficult to breathe and see)<br>1: Granulated (strong smell of sulfur)<br>2: Dense/Wet (roads not passable)</p>                                                                                                                                                |
|               |              |                                                                                                                                                                                                                                                                                                                                                                                             |


# API

The Petabencana Data API provides a number of endpoints for interacting with the system. These are summarised below, full details of the endpoints together with worked examples can be found in the pages that follow.

## Summary of Endpoints

Details of each endpoint are as follows.

| Endpoint            | Description         | Methods | Protected |
| ------------------- | ------------------- | ------- | --------- |
| /cards              | GRASP Cards         | GET,PUT | Yes       |
| /cities             | Cities              | GET     | No        |
| /feeds              | Feeds               | GET,PUT | Yes       |
| /floodgauges        | Flood Gauges        | GET,PUT | No        |
| /floods             | Floods              | GET     | Partial   |
| /floods/archive     | Floods Archive      | GET     | No        |
| /floods/timeseries  | Floods Time Series  | GET     | No        |
| /infrastructure     | Infrastructure      | GET     | No        |
| /reports            | Reports             | GET     | No        |
| /reports/archive    | Reports Archive     | GET     | No        |
| /reports/timeseries | Reports Time Series | GET     | No        |
| /stats/\*           | Summary Statistics  | GET     | No        |


# Cards

MapaKalamidad report cards for disaster events. Note: [authentication](https://docs.petabencana.id/general/authentication.html) is required to make updates to cards.

## Request Format

| URL Parameter | Description                                                                                                                     | Format                      | Required |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | -------- |
| cardId        | Unique identifier of the card we wish to work with, this is generated by the system when the initial card is created (required) | String (7 to 14 characters) | Yes      |

| Attribute   | Description                               | Format                                                                | Required |
| ----------- | ----------------------------------------- | --------------------------------------------------------------------- | -------- |
| card\_data  | User data collected in card interface     | JSON                                                                  | Yes      |
| text        | Description of the disaster event         | String                                                                | No       |
| image\_id   | Identifier of the associated card image   | String                                                                | No       |
| created\_at | Date and time the card was created        | Date ([ISO 8601](http://www.iso.org/iso/home/standards/iso8601.htm))  | Yes      |
| location    | Geographic location of the disaster event | Lat/Long in [ESPG:4326](http://spatialreference.org/ref/epsg/wgs-84/) | Yes      |

### Note on card\_data

Card data requires the object `report_type` to exist. Where `disaster_type` is set to 'flood' then the object `flood_depth` should also exist adjacent to `report_type`. Where the `disaster_type` is 'prep' then `report_type` should be one of the types as specified in server config.js.

| Disaster Type | report\_type | Attribute details                                                                                                                                                                                                                                           |
| ------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Flood         | flood        | <p>flood\_depth: flood severity based on depth in cm<br></p><p>< 70 cm : Minor</p><p>70 - 150 cm : Moderate</p><p>150 cm : Severe</p>                                                                                                                       |
| Earthquake    | road         | <p>accessabilityFailure: the level of road damage affected by earthquake<br><br>0 : < 0,5 m (No Vehicle Access)<br>1 : 0,6 - 1 m (2 and 3-Wheel Vehicle)<br>2 or 3 : 1.1 - 1.8 m (4-Wheel Vehicle)<br>4 : >1,9 m Large Vehicles (Large SUVs and Trucks)</p> |
| Earthquake    | structure    | <p>structureFailure: the level of structure damage affected by earthquake</p><p>0 : Observed Shaking<br>1 : Minor Damage<br>2 : Major Damage<br>3 : Fully Collapsed</p>                                                                                     |
| Volcano       | volcanic     | <p>volcanicSigns: Volcano Observations</p><p>0 : Water Sources are drying up/Contaminated<br>1 : Declining plant health<br>2 : Unusual Animal Behaviour<br>3 : Frequent Earthquake Tremors<br>4 : Frequent Rumbling Sounds</p>                              |
| Volcano       | ashfall      | <p>smogImpact: the level of ashfall situation</p><p>0 : Fine/Dry<br>1 : Granulated<br>2 : Dense/Wet</p>                                                                                                                                                     |
| Typhoon       | wind         | <p>impact: level of disruption caused by extreme wind</p><p>0 : Low Disruption<br>1 : Medium Disruption<br>2 : High Disruption</p>                                                                                                                          |
| Typhoon       | flood        | <p>flood\_depth: flood severity based on depth in cm<br></p><p>< 70 cm : Minor</p><p>70 - 150 cm : Moderate</p><p>150 cm : Severe</p>                                                                                                                       |
| Typhoon       | storm        | <p>impact: Disruption Levels<br></p><p>Low</p><p>Medium</p><p>High</p>                                                                                                                                                                                      |

For example a card with flood data including flood\_depth:

```javascript
  "disaster_type": "flood",
  "card_data":{
    "report_type": "flood",
    "flood_depth": 50
  }
```

## GET /cards/:cardId

Retrieve details of a card:

Here is a simple call to GET a card:

```
curl -X GET -H "X-Api-Key: API_KEY_GOES_HERE" "https://data.mapakalamidad.ph/cards/abcdefg"
```

The card was found:

```javascript
{
  "statusCode": 200,
  "result": {
    "pkey": "2",
    "card_id": "abcdefg",
    "username": "user",
    "network": "test",
    "language": "en",
    "received": true,
    "report_id": "1"
  }
}
```

The card does not exist:

```javascript
{
  "statusCode": 404,
  "found": false,
  "result": null
}
```

## PUT /cards/:cardId

Update a card with details a disaster event report:

Here is a simple call to PUT a card:

```
curl -X PUT -H "X-Api-Key: API_KEY_GOES_HERE" -d '{
    "text": "test card",
    "disaster_type": "flood"
    "card_data":
      {
        "report_type": "flood",
        "flood_depth": 101
      },
    "created_at":"2016-12-09T11:32:52.011Z",
    "location": {
        "lat": -6.149531,
        "lng": 106.869342
    }
}' "https://data.mapakalamidad.ph/cards/abcdefg"
```

Card was successfully created:

```javascript
{
  "statusCode": 200,
  "cardId": "abcdefg",
  "created": true
}
```

The card does not exist:

```javascript
{
  "statusCode": 404,
  "cardId": "abcdefg",
  "message": "No card exists with id 'abcdefg'"
}
```

The report already exists for the card:

```javascript
{
  "statusCode": 409,
  "cardId": "abcdefg",
  "message": "Report already received for card 'abcdefg'"
}
```

## GET /cards/:cardId/images

GET a signed S3 URL to upload a card report, this must be done after the card report has been created and only one image can exist for a given card.

NOTE: After an image is submitted a server-side process shrinks the image to a standard size and there may be a small time lag of a few seconds before the image goes "live".

Here is a simple call to GET a new signed S3 URL for image upload:

```
curl -X GET \
  https://api-server-dev.riskmap.in/cards/HJID8CWN-/images
```

Signed S3 URL successfully generated:

```javascript
{"signedRequest":"https://riskmap-image-uploads.s3.ap-south-1.amazonaws.com/originals/BJbTHR-Vb.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJFMR3NR7BXZ5X7DA%2F20170629%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20170629T012002Z&X-Amz-Expires=900&X-Amz-Signature=ad10a53555205fa18ecfa07da52eb0349ed1c8bda66fe2de0fa9c445c61b7c62&X-Amz-SignedHeaders=host","url":"https://s3.ap-south-1.amazonaws.com/riskmap-image-uploads/originals/BJbTHR-Vb.jpg"}
```


# Feeds

MapaKalamidad utilises data feeds from a number of third party sources. This endpoint allows the creation of data into the system for authorised users. Note: [authentication](https://docs.petabencana.id/general/authentication.html) is required to post data through the /feeds endpoint.

## POST /feeds

Add a report to the system from [Qlue](http://www.qlue.co.id/). The following attributes are supported for Qlue reports:

| Attribute      | Description                                                                  | Format                                                                | Required |
| -------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------- | -------- |
| post\_id       | Unique qlue identifier for the report                                        | Integer                                                               | Yes      |
| created\_at    | Date and time the card was created                                           | Date ([ISO 8601](http://www.iso.org/iso/home/standards/iso8601.htm))  | Yes      |
| title          | The title of the report being filed                                          | String                                                                | No       |
| text           | Description of the disaster event                                            | String                                                                | No       |
| image\_url     | URL of the associated image                                                  | String                                                                | No       |
| disaster\_type | What type of disaster is being reported (currently only `flood`is supported) | String                                                                | Yes      |
| location       | Geographic location of the disaster event                                    | Lat/Long in [ESPG:4326](http://spatialreference.org/ref/epsg/wgs-84/) | Yes      |

Report was successfully created:

```javascript
{
  "post_id": 1234567802,
  "created": true
}
```

The request was successful however the report already exists:

```javascript
{
  "post_id": 1234567802,
  "created": false,
  "message": "1234567802 already exists in reports table"
}
```


# Crowdsourced Reports

Live disaster reports, by default reports will be returned for the last hour.

## Request Format

| Query Parameter | Description                                                                                                 | Format | Required |
| --------------- | ----------------------------------------------------------------------------------------------------------- | ------ | -------- |
| admin           | Which city do we wish to return infrastructure for? (see [supported areas](/master/general/supported-area)) | String | No       |
| format          | Which format should we return results in? (one of `json`, defaults to `json`)                               | String | No       |
| geoformat       | What format should geographic results use (one of `topojson`, `geojson` defaults to `topojson`)             | String | No       |
| timeperiod      | What time period (in seconds) to list reports for, must be strictly between 1 and 604800 (1 week)           | Number | No       |

## GET /reports

List all current reports from Philippines.

Note : Please include a User-Agent header in all of your requests. The User-Agent header helps us identify your requests and troubleshoot any issues you may have. To set the User-Agent header, add the following line to your request headers:

```
curl --user-agent "YOUR-UA-STRING" "https://api.mapakalamidad.ph/reports"
```

List all current flood reports from Philippines in geojson format.

```
curl --user-agent "YOUR-UA-STRING" "https://api.mapakalamidad.ph/reports?geoformat=geojson"
```

Results are as follows:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "Topology",
    "objects": {
      "output": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Point",
            "properties": {
              "pkey": "5519",
              "created_at": "2016-12-09T21:37:00.000Z",
              "source": "qlue",
              "status": "confirmed",
              "url": null,
              "image_url": "https://lh3.googleusercontent.com/ByClSrW6QhFkBxUhZo0rFt6eiVdvnEHisSzsgjaC9KxdGAQ6CYksTZRA1rcNP9cBGZiv6s4Vp5D8NzkAjPyrBs6c6R4h=s480-c",
              "disaster_type": "flood",
              "report_data": null,
              "tags": {
                "instance_region_code": "jbd",
                "local_area_id": "350"
              },
              "title": " ",
              "text": "Perlu penataan dan dirapihkan @ahokbtp semoga bisa lbh baik, bersih dan teratur"
            },
            "coordinates": [
              0,
              0
            ]
          }
        ]
      }
    },
    "arcs": [],
    "transform": {
      "scale": [
        1,
        1
      ],
      "translate": [
        106.817276,
        -6.138229
      ]
    },
    "bbox": [
      106.817276,
      -6.138229,
      106.817276,
      -6.138229
    ]
  }
}
```


# Crowdsourced Reports/Archive

Archive of flood reports (see [Reports endpoint](/master/routes/reports) documentation), presented as a JSON with all the flood reports received within the specified time period.

Note: [authentication](https://docs.petabencana.id/general/authentication.html) is required to get archived reports.

## Request Format

| Query Parameter | Description                                                                                                      | Format                                              | Required |
| --------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | -------- |
| start           | Start time for archive period                                                                                    | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |
| end             | End time for archive period                                                                                      | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |
| admin           | Which city do we wish to return infrastructure for? (one of [supported areas](/master/general/supported-area)`)` | String                                              | No       |
| geoformat       | What format should geographic results use (one of `topojson`, `geojson` defaults to `topojson`)                  | String                                              | No       |

Note that time zone must be specified as +/- UTC offset which will require HTML character encoding (e.g. +0700 becomes %2B0700).

## Get /reports/archive

Note : Please include a User-Agent header in all of your requests. The User-Agent header helps us identify your requests and troubleshoot any issues you may have. To set the User-Agent header, add the following line to your request headers:

List flood reports received within specified time window

```
curl --user-agent "YOUR-UA-STRING" "X-Api-Key: API_KEY_GOES_HERE" "https://api.mapakalamidad.ph/reports/archive?start=2017-12-04T00%3A00%3A00%2B0700&end=2017-12-06T05%3A00%3A00%2B0700&geoformat=geojson"
```

Results are as follows:

```javascript
{
    "statusCode": 200,
    "result": {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [
                        106.815842,
                        -6.183179
                    ]
                },
                "properties": {
                    "pkey": "0001",
                    "created_at": "2017-12-04T09:51:00.000Z",
                    "source": "qlue",
                    "status": "confirmed",
                    "url": null,
                    "image_url": null,
                    "disaster_type": "flood",
                    "report_data": null,
                    "tags": {
                        "instance_region_code": "jbd",
                        "local_area_id": "782"
                    },
                    "title": " ",
                    "text": "#flood report"
                }
            }
          ]
        }
      }
```


# Crowdsourced Reports/Timeseries

Time series of flood reports (see [Reports endpoint](/master/routes/reports) documentation), presented as the count of flood reports every hour within the specified time period. Count is recorded alongside an hourly timestamp in ISO8601 format at UTC+0.

## Request Format

| Query Parameter | Description                      | Format                                              | Required |
| --------------- | -------------------------------- | --------------------------------------------------- | -------- |
| start           | Start time for timeseries period | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |
| end             | End time for timeseries period   | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |

Note that time zone must be specified as +/- UTC offset which will require HTML character encoding (e.g. +0700 becomes %2B0700).

## Get /reports/timeseries

Note : Please include a User-Agent header in all of your requests. The User-Agent header helps us identify your requests and troubleshoot any issues you may have. To set the User-Agent header, add the following line to your request headers:

Get count of flood reports within specified time period.

```
    curl --user-agent "YOUR-UA-STRING" "https://api.mapakalamidad.ph/reports/timeseries?start=2021-11-26T12%3A00%3A00%2B0700&end=2021-11-26T15%3A00%3A00%2B0700"
```

Results are as follows:

```javascript
    {
        "statusCode": 200,
        "result": [
            {
                "ts": "2017-11-26T05:00:00.000Z",
                "count": "0"
            },
            {
                "ts": "2017-11-26T06:00:00.000Z",
                "count": "0"
            },
            {
                "ts": "2017-11-26T07:00:00.000Z",
                "count": "2"
            },
            {
                "ts": "2017-11-26T08:00:00.000Z",
                "count": "3"
            }
        ]
    }
```


# Stats

Some summary statistics:

* [/stats/reportsSummary](/master/routes/stats/reportssummary) : summary of reports


# Stats - Reports Summary

Count of reports by source ( "grasp" being combined Twitter, Facebook , Telegram and Website), by default reports will be returned for the last 3 hours.

## Request Format

| Query Parameter | Description                                                                                                    | Format | Required |
| --------------- | -------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| admin           | Which city do we wish to return infrastructure for? (one of [supported areas](/master/general/supported-area)) | String | No       |
| timeperiod      | What time period (in seconds) to list reports for, must be strictly between 1 and 604800 (1 week)              | Number | No       |

## GET /stats/getReportsSummary

```
curl "https://data.mapakalmidad.ph/stats/reportsSummary?admin=PH-01"
```

Results are as follows:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "Topology",
    "objects": {
      "output": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Point",
            "properties": {
              "pkey": "5519",
              "created_at": "2016-12-09T21:37:00.000Z",
              "source": "grasp",
              "status": "confirmed",
              "url": null,
              "image_url": "https://lh3.googleusercontent.com/ByClSrW6QhFkBxUhZo0rFt6eiVdvnEHisSzsgjaC9KxdGAQ6CYksTZRA1rcNP9cBGZiv6s4Vp5D8NzkAjPyrBs6c6R4h=s480-c",
              "disaster_type": "flood",
              "report_data": null,
              "tags": {
                "instance_region_code": "PH-01",
                "local_area_id": "350"
              },
              "title": " ",
              "text": "Flood report"
            },
            "coordinates": [
              0,
              0
            ]
          }
        ]
      }
    },
    "arcs": [],
    "transform": {
      "scale": [
        1,
        1
      ],
      "translate": [
        106.817276,
        -6.138229
      ]
    },
    "bbox": [
      106.817276,
      -6.138229,
      106.817276,
      -6.138229
    ]
  }
}
```


# Pagpapakilala

Ang MapaKalamidad ay pinapatakbo ng [Yayasan Peta Bencana](https://info.petabencana.id/), sa tulong ng U.S. Agency for International Development (USAID) sa ilalim ng Cognicity Open Source Software for Next Generation Disaster Risk Management Program bilang isang libre at transparent na plataporma para sa agarang tugon at pamamahala ng kalamidad.

Ang plataporma ay isinasatupad ang kasabihang "people are the best sensors" kung saan ang pinagtibay na ulat ay kinokolekta direkta mula sa mga gumagamit sa daan upang iwasan ang mga hindi mabisang pamamaraan ng pagkolekta at pag proseso ng datos. Ang framework na ito ay lumilikha ng tumpak at real-time na datos na ginawa para sa mga gumagamit, lalo na sa mga first responders.

## MapaKalamidad Data API

Ang MapaKalamidad ay sinusuportahan ng isang data API na naglalantad ng iilang pampubliko at pribadong mga endpoint. Ang sumusunod na dokumentasyon ay nagbibigay-daan sa mga developer na bumangon at tumakbo. Ang proyektong ito ay isang ganap na open-sourced at ang code ay makikita sa MapaKalamidad GitHub. Ang diagram ng arkitektura ay magagamit sa iba’t ibang mga format tulad ng sumusunod:

* [**PDF**](https://github.com/petabencana/petabencana-docs/tree/d8b3cac5b3bc2a65abd49d874bf9c5798e93eb97/petabencana.pdf)
* [**Visio XML**](https://github.com/petabencana/petabencana-docs/tree/d8b3cac5b3bc2a65abd49d874bf9c5798e93eb97/petabencana.vdx)
* [**OmniGraffle**](https://github.com/petabencana/petabencana-docs/tree/d8b3cac5b3bc2a65abd49d874bf9c5798e93eb97/petabencana.graffle.zip)

### Ang aming mga Sponsors

#### Mga Kasama sa Pagpopondo

![USAid](https://3324033962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2Fb3ad4cb1b29087495f3d78ee490657c362e5ea4a.png?generation=1613027636895043\&alt=media)&#x20;

#### Mga Kasama sa Datos

![](https://3324033962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2F12a2fc18eac7ea65dc4ebcde50fc28b64f0e1275.png?generation=1613027638254141\&alt=media)

![](https://lh4.googleusercontent.com/Auo8hDMDMCzCuMD2QWZ2H4Td0sNnIjcnnpX6Q0uAAV-IMjBHhViO0a-aincAOjcwOh1vXPuB4fxNS1-FkGgrM1pEQrAYbcBRnFe25Y3v-r__-H5JcysnngzxlhxYyQnaJaZr3T3q)

![](https://github.com/petabencana/petabencana-docs/tree/d8b3cac5b3bc2a65abd49d874bf9c5798e93eb97/Mapbox_logo.png)

#### Mga Kasama sa Pagpapatupad

![](https://lh3.googleusercontent.com/ryKYQWkFukrGh50DVeIyJwII_QXfH9ofdSDgVtpESQBe1394awMFrIOb4Ttcu9MWpxH7-2JVPP1KQ8x2LHE6A6C0hNy4Z2T4MwQyx9uQfbEVxy0ZZGC-Vp7DUqYpwgFa-3a9RDBC)

![](https://lh3.googleusercontent.com/H8gW0VyDUa1S7ZwRQ2e59qG4Tnmb7Qo59UTzDWxQIm1jc1Z2hnOyPXz-7rqPczyDfaIKEed0fWF58wtbIrpjSDVGJ_ytglkXR4rP2dLz5l7apLAgDe0Th9USpdMBbVpcyx86Pi2Q)

![](https://lh5.googleusercontent.com/39INbdeXc4iSWDnr7r_fKZcPMUIlJagm8i_jQx_XtQYuKJaeiEuEq6xTrJBYjHtOErLTSrvciNTWwsZRNvLgk94MJU4Rc40j2m71Vmg3KUwRLDpKLH169DDW9AEY5nfW9HcYuFnE)

![](https://lh6.googleusercontent.com/kDOIoRA9eQfqalhssYke4GdD2pfPbVBECUU6tmL8s22n8UgUiX7x7uLiRPZ_7PFfPxStA6jOIeAjnkYczzIP-h0g5pJWeygHRSvKsnR4Zgl2riSFyaU05HJoB9t1FdMdfvRoUB5r)

#### Mga Kasama sa Proyekto

![](https://3324033962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2Fd4cb04c472cdcfce42d27d63c8a4c30f19ee5acb.png?generation=1613027636486005\&alt=media) ![](https://3324033962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2F9e00a7b592319e9d532c55cc6d332c4fdc3f4f09.png?generation=1613027638037008\&alt=media) ![](https://3324033962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTEvoZ8lWVUI2ZGFmrW%2Fsync%2Fc8146ddac882b1f1aa93900e32942896891fded9.png?generation=1613027636694275\&alt=media)


# Pangkalahatan

May iilang pamantayan na nalalapat anuman ang API na ginagamit at ang mga ito ay dokumentado sa mga sumusunod na pahina.


# Pagpapatunay

Ang MapaKalamidad API ay naglalantad ng ilang mga protektadong ruta na mangangngailangan ng pagpapatunay upang ma-access.Ginagamit ang JSON Web Token para sa pagpapatunay.\
\
Tanda: Para sa bagong API key, mangyaring makipagugnayan sa MapaKalamidad team.


# Pag-bebersyon

Ang API ay naka bersyon sa version string na nakatukoy sa batayang URL na maaring madagdagan mula sa iba pang mga API.

Palaging hinihikayat ang paggamit ng pinakabagong magagamit na API.

Ang mga pagbabago ay kinokonsiderang katugma pabalik at hindi mangangailangan dagdagan ang string version.

* Pagdagdag ng mga pag-aari sa mga bagay ng JSON
* Pagdagdag ng mga bagong parameter
* Pagbabago ng bilang ng mga bagay sa iisang listing request;
* Ang istraktura o haba ng mga identifier na nabuo ng API
* Ang pagbabago ng mga maling mensahe

Ang mga pagbabagong ito ay itinuturing na backwards incompatible o hindi tugmang paurong, at kakailanganin ang version string na madagdagan:

* Ang pagtanggal ng mga pag-aari ng mga bagay ng JSON;
* Pagbabago ng istraktura ng URL ng API

Ang kasulukuyang bersyon ay v1<br>


# Rate Limits

Gumagamit ang MapaKalamidad API ng rate limiting na nagbibigay hangganan sa bilang ng mga hiling na maigagamit kontra sa endpoint. Kapag lumagpas ka sa hangganan, ang inyong hiling ay mapipigilan at makatatangap ka ng HTTP 429 Masyadong Maraming Humihiling ng mga tugon mula sa API.

Hinihikayat kang laging manatili sa loob ng iyong inilaan na quota at magpatupad ng mga pagsubok sa iyong code kung saan na aangkop.<br>


# CORS

[Cross-Origin Requests](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) ay sinusuporta na walang paghihigpit sa domain upang mapadali ang pagsasama sa mga browser based applications.


# HTTPS

Ang pag-access sa lahat ng mga API sa HTTPS ay sapilitan. Ang mga kahilingan na sinimulan sa HTTP ay agad iaangat sa HTTPS.


# Coordinates

Ang spatial reference system na ginagamit ay [WGS84](https://en.wikipedia.org/wiki/World_Geodetic_System).


# Error Codes

Sumusunod ang MapaKalamidad sa pamantayan ng HTTP Status Codes upang maghatid ng mga pagkakamali kasama ang isang mensahe na json formmatted na nagbibigay impormasyon ukol sa ugat ng pagkakamali. Ang mga pangunahing ginamit na codes ay ang sumusunod:

## 4xx Errors

Ipinapahiwatig ng mga pagkakamaling nagsisimula sa 4 ang mga isyu sa panig ng kliyente na dapat ma resolba bago muling magtanong ng serbisyo tulad ng:

* **400 Bad Request** - madalas sanhi ito ng isang maling query parameter tulad ng:`"child \"type\" fails because [\"type\" must be one of [floodgates, pumps, waterways]]"`
* **403 Forbidden** -  ang tanda ng pagpapatunay ay imbalido
* **404 Not Found** - hindi mahanap ang pinagkukunan, maari na ito ay nagpapahiwatig nang maling endpoint o sinusubukang mag rekord tulad ng isang report na hindi namamalagi.
* **409 Conflict** - tunay ang pinagkukunan subalit kapag pinayagan ang hiling, magkakaroon ng hindi pagkakasundo na mabubuo sa sistema, tulad ng pag-file ng ulat sa card kung saan ang ulat ay namamalagi.
* **415 Unsupported Media Type** - ang file na ini-upload ay hindi sinusuporta ng sistema - kadalasan ibig sabihin nito na may binary file tulad ng isang imahe ay ini-iupload subalit ang Content-Type header kasama ang nauugnay na MIME type (e.g. ‘image/jpeg’) ay hindi pa nabibigay.
* **429 Too Many Requests** - sumobra na ang quota ng mga hilig bawat segundo o bawat araw.

## 5xx Errors

Errors starting with a 5 generally indicate a server side fault and should be immediately:

Madalas ang mga pagkakamaling nagsisimula sa 5 ay nagpapahiwatig ng depekto sa server at dapat ma resolba agad-agad:

* **500 Internal Server Error** - isang pangkalahatang pagkakamali sa panig ng server.&#x20;
* **503 Service Unavailable** - bagsak ang serbisyo at hindi maka-responde sa mga hiling.&#x20;


# Mga Uri ng Nilalaman

Bilang default ibinabalik ng MapaKalamidad API ang JSON para sa lahat ng mga tawag at inaasahan ang POST requests na ibigay ang mga na-format na katawan ng JSON maliban na lamang kung payuhan. Ginagamit ang pag-encode ng UTF-8 sa lahat ng mga kahilingan at tugon.

Kung saan ibinabalik ang Geographic data na mai-encode bilang [TopoJSON](https://github.com/topojson/topojson/wiki) bilang default. Sinusuportahan din ang [GeoJson ](https://geojson.org/)kung kinakailangan, sa pamamagitan ng pagbibigay.`format=topojson in the API call. More details of this can be found in the specific API route documentation. In addition to TopoJSON and GeoJson we provide a public feed of real-time flood information using the`[`Common Alerting Protocol`](https://en.wikipedia.org/wiki/Common_Alerting_Protocol)`standard.`


# Mga Halimbawa

Ang APIs all feature ay gumagana sa mga halimbawa na may sample HTTPS calls. Dahil kinakailangan pumasa sa mga headers ng pagpapatunay, sa iilang mga kaso upang maka-konek, hindi maaring mapatakbo ang mga ito sa isang web browser.  Ang bawat halimbawa ay nagpapakita ng isang utos na cURL command na mgagamit sa WIndows, Mac o Linux. Tandaan na para sa mga protektadong ruta kakailanganin mong ipasok ang iyong sariling token ng JWT para gumana ang mga ito.

Kung hindi ka komportable sa command line o mas gusto lang ang isang user interface, ang [Postman ](https://www.postman.com/)ay isang kamangha-manghang libreng tool para sa pag-eksperimento sa mga API.


# API

Nagbibigay ang MapaKalamidad Data API ng iilang endpots upang makipag-ugnayan sa system. Ang mga ito ay buod sa ibaba, ang buong detayle ng mga endpoints kasama ang mga nagawang halimbawa ay matatagpuan sa mga sumusunod na pahina:

## Buod ng mga Endpoints

Ang mga detalye ng bawat endpoint ay ang mga sumusunod:

| Paglalarawan        | Pamamaraan          | Protected |         |
| ------------------- | ------------------- | --------- | ------- |
| /cards              | GRASP Cards         | GET,PUT   | Yes     |
| /cities             | Cities              | GET       | No      |
| /feeds              | Feeds               | GET,PUT   | Yes     |
| /floodgauges        | Flood Gauges        | GET,PUT   | No      |
| /floods             | Floods              | GET       | Partial |
| /floods/archive     | Floods Archive      | GET       | No      |
| /floods/timeseries  | Floods Time Series  | GET       | No      |
| /infrastructure     | Infrastructure      | GET       | No      |
| /reports            | Reports             | GET       | No      |
| /reports/archive    | Reports Archive     | GET       | No      |
| /reports/timeseries | Reports Time Series | GET       | No      |
| /stats/\*           | Summary Statistics  | GET       | No      |


# Cards

Ang mga card report ng MapaKalamidad para sa mga kaganapan ng sakuna. Tandaan: Kinakailangan ang pagpapatunay (authentication) upang maka-update sa mga card.

## Format ng Kahilingan

| URL Parameter | Paglalarawan                                                                                                                        | Format                      | Required |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------- | -------- |
| cardId        | Natatanging pagkakakilanlan ng card na nais naming gumana, nabubuo ito ng system kapag nilikha ang sinimulang card. (Kinakailangan) | String (7 to 14 characters) | Yes      |

| Attribute   | Paglalarawan                                          | Format                                                                | Required |
| ----------- | ----------------------------------------------------- | --------------------------------------------------------------------- | -------- |
| card\_data  | Nakolekta ang datos ng gumagamit sa interface ng card | JSON                                                                  | Yes      |
| text        | Paglalarawan ng kaganapan sa sakina                   | String                                                                | No       |
| image\_id   | Tukoy ng nauugnay na imahe ng card                    | String                                                                | No       |
| created\_at | Petsa at oras ang card ay nilikha                     | Date ([ISO 8601](http://www.iso.org/iso/home/standards/iso8601.htm))  | Yes      |
| location    | Lugar ng Heograpiya ng kaganapan sa sakuna            | Lat/Long in [ESPG:4326](http://spatialreference.org/ref/epsg/wgs-84/) | Yes      |

### Tanda sa card\_data

Kinakailangan ng Card data na ang object `report_type` ay umiiral. Kung saan `disaster_type` ay naka 'flood' at ang object `flood_depth` ay umiiral kasunod ang`report_type`.  Saan ang `disaster_type`  ay 'prep' pagkatapos ang`report_type` ay dapat isa sa mga tipo na nakalista sa server config.js \
\
Halimbawa ng isang card na may data ng pagbaha kasama ang flood \_depth:

```javascript
   "disaster_type": "flood",
   "card_data":{
    "report_type": "flood",
    "flood_depth": 50
  }
```

O kaya, isang card na may ulat ng data bago ang pagbaha tungkol sa isang kanal.

```javascript
  "disaster_type": "prep",
  "card_data":{
    "report_type":"drain"
  }
```

## KUMUHA/cards/:cardId

Kunin ang mga detalye ng isang card:

Narito ang isang simpleng halimbawa upang makakuha (GET) ng isang card:

```
curl -X GET -H "X-Api-Key: API_KEY_GOES_HERE" "https://data.petabencana.id/cards/abcdefg"
```

Nahanap ang card:

```javascript
{
  "statusCode": 200,
  "result": {
    "pkey": "2",
    "card_id": "abcdefg",
    "username": "user",
    "network": "test",
    "language": "en",
    "received": true,
    "report_id": "1"
  }
}
```

Hindi umiiral ang card:

```javascript
{
  "statusCode": 404,
  "found": false,
  "result": null
}
```

## ILAGAY/cards/:cardId

I-update ang card kasama ang mga detalye tungkol sa isang ulat tungkol sa kalamidad:

Ito ay isang simpleng halimbawa paano ilagay (PUT) ang card:

```
curl -X PUT -H "X-Api-Key: API_KEY_GOES_HERE" -d '{
    "text": "test card",
    "disaster_type": "flood"
    "card_data":
      {
        "report_type": "flood",
        "flood_depth": 101
      },
    "created_at":"2016-12-09T11:32:52.011Z",
    "location": {
        "lat": -6.149531,
        "lng": 106.869342
    }
}' "https://data.petabencana.id/cards/abcdefg"
```

Matagumpay nagawa ang card:&#x20;

```javascript
{
  "statusCode": 200,
  "cardId": "abcdefg",
  "created": true
}
```

Hindi umiiral ang card:&#x20;

```javascript
{
  "statusCode": 404,
  "cardId": "abcdefg",
  "message": "No card exists with id 'abcdefg'"
}
```

Mayroon nang ulat para sa card:&#x20;

```javascript
{
  "statusCode": 409,
  "cardId": "abcdefg",
  "message": "Report already received for card 'abcdefg'"
}
```

## KUMUHA/cards/:cardId/images

KUMUHA ng isang naka-sign na S3 URL upang mag-upload ng isang ulat sa card, dapat itong gawin pagkatapos malikha ang ulat ng card at isang imahe lamang ang maaring magkaroon para sa isang naibigay na card.

TANDAAN: Matapos isumite ang isang imahe sa servier-side ay pinapaliit ang imahe sa isang karaniwang sukat at maaaring mayroong kaunting lag ng ilang segundo bago ang imahe ay maging "live".

Narito ang isang simpleng halimbawa upang makakuha ng isang bagong naka-sign na S3 URL para sa pag-upload ng imahe:&#x20;

```
curl -X GET \
  https://api-server-dev.riskmap.in/cards/HJID8CWN-/images
```

Matagumpay na nabuo ang naka-sign na S3 URL:

```javascript
{"signedRequest":"https://riskmap-image-uploads.s3.ap-south-1.amazonaws.com/originals/BJbTHR-Vb.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJFMR3NR7BXZ5X7DA%2F20170629%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20170629T012002Z&X-Amz-Expires=900&X-Amz-Signature=ad10a53555205fa18ecfa07da52eb0349ed1c8bda66fe2de0fa9c445c61b7c62&X-Amz-SignedHeaders=host","url":"https://s3.ap-south-1.amazonaws.com/riskmap-image-uploads/originals/BJbTHR-Vb.jpg"}
```


# Cities

Sinusuportahan ng MapaKalamidad ang maraming mga lungsod na tinutukoy ng isang pangheograpiyang lugar. Ibabalik ng endpoint na ito ang mga sinusuportahang lungsod kasama ang kani-kanilang mga hangganang pangheograpiya.

## Request Format

| Query Parameter | Paglalarawan                                                                                                                           | Format | Required |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| format          | Aling format ang dapat nating ibalik ang mga resulta? (isang `json`, babalik sa`json`)                                                 | String | No       |
| geoformat       | Anong format ang dapat gamitin  ng geographic results o ang resulta sa heyograpiya (isang `topojson`, `geojson` babalik sa `topojson`) | String | No       |

## KUMUHA/cities

Ibalik ang lahat ng mga lungsod sa format na default (topojson).

```
curl "https://data.petabencana.id/cities"
```

Ang mga resulta ay ang mga sumusunod:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "Topology",
    "objects": {
      "output": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Polygon",
            "properties": {
              "code": "jbd",
              "name": "Jabodetabek"
            },
            "arcs": [
              [
                0
              ]
            ]
          },
          {
            "type": "Polygon",
            "properties": {
              "code": "bdg",
              "name": "Bandung"
            },
            "arcs": [
              [
                1
              ]
            ]
          },
          {
            "type": "Polygon",
            "properties": {
              "code": "sby",
              "name": "Surabaya"
            },
            "arcs": [
              [
                2
              ]
            ]
          }
        ]
      }
    },
    "arcs": [
      [
        [
          0,
          4891
        ],
        [
          1061,
          0
        ],
        [
          0,
          5108
        ],
        [
          -1061,
          0
        ],
        [
          0,
          -5108
        ]
      ],
      [
        [
          1357,
          2305
        ],
        [
          857,
          0
        ],
        [
          0,
          2976
        ],
        [
          -857,
          0
        ],
        [
          0,
          -2976
        ]
      ],
      [
        [
          9031,
          0
        ],
        [
          968,
          0
        ],
        [
          0,
          3207
        ],
        [
          -968,
          0
        ],
        [
          0,
          -3207
        ]
      ]
    ],
    "transform": {
      "scale": [
        0.0006552455245524552,
        0.000167006700670067
      ],
      "translate": [
        106.48,
        -7.5499
      ]
    },
    "bbox": [
      106.48,
      -7.5499,
      113.0318,
      -5.88
    ]
  }
}
```

Ibalik ang lahat ng mga lungsod sa format na default (geojson).

```
curl "https://data.petabencana.id/cities?geoformat=geojson"
```

Ang mga resulta ay ang mga sumusunod:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                106.48,
                -6.733
              ],
              [
                107.175,
                -6.733
              ],
              [
                107.175,
                -5.88
              ],
              [
                106.48,
                -5.88
              ],
              [
                106.48,
                -6.733
              ]
            ]
          ]
        },
        "properties": {
          "code": "jbd",
          "name": "Jabodetabek"
        }
      },
      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                107.369,
                -7.165
              ],
              [
                107.931,
                -7.165
              ],
              [
                107.931,
                -6.668
              ],
              [
                107.369,
                -6.668
              ],
              [
                107.369,
                -7.165
              ]
            ]
          ]
        },
        "properties": {
          "code": "bdg",
          "name": "Bandung"
        }
      },
      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                112.3975,
                -7.5499
              ],
              [
                113.0318,
                -7.5499
              ],
              [
                113.0318,
                -7.0143
              ],
              [
                112.3975,
                -7.0143
              ],
              [
                112.3975,
                -7.5499
              ]
            ]
          ]
        },
        "properties": {
          "code": "sby",
          "name": "Surabaya"
        }
      }
    ]
  }
}
```


# Feeds

Gumagamit ang MapaKalamidad ng mga data feed mula sa mga iilang third party sources. Pinapayagan ng endpoint na ito ang paglikha ng data sa system para sa mga awtorisadong gumagamit. Tandaan: Kinakailangan ang [pagpapatunay ](https://docs.petabencana.id/general/authentication)upang ma-post ang data sa pamamagitan ng /feeds endpoint.

## POST /feeds/qlue

Magdagdag ng isang ulat sa system mula sa [Qlue](https://www.qlue.co.id/). Sinusuportahan ang mga sumusnod na katangian para sa mga ulat ng Qlue:

| Katangian      | Paglalarawan                                                                   | Format                                                                | Required |
| -------------- | ------------------------------------------------------------------------------ | --------------------------------------------------------------------- | -------- |
| post\_id       | Natatanging tagatukoy ng Qlue para sa ulat                                     | Integer                                                               | Yes      |
| created\_at    | Petsa at oras ang card ay nilikha                                              | Date ([ISO 8601](http://www.iso.org/iso/home/standards/iso8601.htm))  | Yes      |
| title          | Ang Pamagat ng ulat na iniharap                                                | String                                                                | No       |
| text           | Paglalarawan ng kaganapan sa kalamidad                                         | String                                                                | No       |
| image\_url     | URL na nauugnay na imahe                                                       | String                                                                | No       |
| qlue\_city     | Mula sa aling lungsod ang nabuong ulat (dapat ay isa sa`Quezon City, Pampanga` | String                                                                | Yes      |
| disaster\_type | Anong uri ng sakuna ang naiuulat (sa kasulukuyan`baha` lamang ang suportado)   | String                                                                | Yes      |
| location       | Lugar ng heograpiya ng kaganapan ng kalamidad                                  | Lat/Long in [ESPG:4326](http://spatialreference.org/ref/epsg/wgs-84/) | Yes      |

Here is a simple call to POST a new Qlue report:

```
curl -X POST -H "X-Api-Key: API_KEY_GOES_HERE" -d '{
    "post_id":1234567802,
    "created_at":"2016-12-09T11:32:52.011Z",
    "image_url":"http://myimg",
    "qlue_city":"jabodetabek",
    "disaster_type":"flood",
    "text":"A big flood",
    "location": {
        "lat": -6.149531,
        "lng": 106.869342
    }
}' "https://data.petabencana.id/feeds/qlue"
```

Matagumpay na nagawa ang ulat:

```javascript
{
  "post_id": 1234567802,
  "created": true
}
```

Ang kahilingan ay matagumpay subalit mayroon nang ulat:

```javascript
{
  "post_id": 1234567802,
  "created": false,
  "message": "1234567802 already exists in reports table"
}
```


# Flood Gauges

Ang mga live flood gauge reports, kadalasan, ay ibabalik sa huling oras.

## Format ng Kahilingan

| Query Parameter | Paglalarawan                                                                                                         | Format | Required |
| --------------- | -------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| city            | Aling lungsod ang nais nating ibalik ang mga imprastraktura? (isa sa `bdg`, `jbd`, `sby`)                            | String | No       |
| format          | Aling format ang dapat nating ibalik? (isa sa`json`, defaults to `json`)                                             | String | No       |
| geoformat       | Aling format ang dapat gamitin ang mga resulta sa heyograpiya? (isa sa `topojson`, `geojson` defaults to `topojson`) | String | No       |

## KUMUHA /floodgauges

Ilista ang lahat ng kasalukuyang ulat sa gauge ng baha para sa Quezon CIty and Pampanga.

```
curl "https://data.petabencana.id/floodgauges?city=jbd"
```

Ang mga resulta ay ang mga sumusunod:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "Topology",
    "objects": {
      "output": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Point",
            "properties": {
              "gaugeid": "TMA00001",
              "gaugenameid": "Bendung Katulampa",
              "observations": [
                {
                  "f1": "2016-12-09T04:00:00+00:00",
                  "f2": 30,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T05:00:00+00:00",
                  "f2": 30,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T06:00:00+00:00",
                  "f2": 30,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T07:00:00+00:00",
                  "f2": 30,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T08:00:00+00:00",
                  "f2": 40,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T09:00:00+00:00",
                  "f2": 40,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T10:00:00+00:00",
                  "f2": 40,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T11:00:00+00:00",
                  "f2": 40,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T12:00:00+00:00",
                  "f2": 40,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T13:00:00+00:00",
                  "f2": 40,
                  "f3": 4,
                  "f4": "SIAGA IV "
                }
              ]
            },
            "coordinates": [
              6271,
              0
            ]
          },
          {
            "type": "Point",
            "properties": {
              "gaugeid": "TMA00002",
              "gaugenameid": "Pos Depok",
              "observations": [
                {
                  "f1": "2016-12-09T04:00:00+00:00",
                  "f2": 100,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T05:00:00+00:00",
                  "f2": 100,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T06:00:00+00:00",
                  "f2": 100,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T07:00:00+00:00",
                  "f2": 100,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T08:00:00+00:00",
                  "f2": 100,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T09:00:00+00:00",
                  "f2": 100,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T10:00:00+00:00",
                  "f2": 100,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T11:00:00+00:00",
                  "f2": 95,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T12:00:00+00:00",
                  "f2": 95,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T13:00:00+00:00",
                  "f2": 95,
                  "f3": 4,
                  "f4": "SIAGA IV "
                }
              ]
            },
            "coordinates": [
              5354,
              3943
            ]
          },
          // etc. etc. //
          {
            "type": "Point",
            "properties": {
              "gaugeid": "TMA00012",
              "gaugenameid": "Waduk Pluit",
              "observations": [
                {
                  "f1": "2016-12-09T04:00:00+00:00",
                  "f2": -165,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T05:00:00+00:00",
                  "f2": -170,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T06:00:00+00:00",
                  "f2": -175,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T07:00:00+00:00",
                  "f2": -175,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T08:00:00+00:00",
                  "f2": -175,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T09:00:00+00:00",
                  "f2": -175,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T10:00:00+00:00",
                  "f2": -175,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T11:00:00+00:00",
                  "f2": -175,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T12:00:00+00:00",
                  "f2": -175,
                  "f3": 4,
                  "f4": "SIAGA IV "
                },
                {
                  "f1": "2016-12-09T13:00:00+00:00",
                  "f2": -170,
                  "f3": 4,
                  "f4": "SIAGA IV "
                }
              ]
            },
            "coordinates": [
              4559,
              9999
            ]
          }
        ]
      }
    },
    "arcs": [],
    "transform": {
      "scale": [
        0.00002272427242724299,
        0.000052198219821982215
      ],
      "translate": [
        106.69416,
        -6.63304
      ]
    },
    "bbox": [
      106.69416,
      -6.63304,
      106.92138,
      -6.11111
    ]
  }
}
```


# Baha

Impormasyon ng live na pagbaha - ayon sa lungsod, ng estado ng baha (kung kinakailangan). SInusuportahan ang /estado endpoint kung saan ay hindi pang-heograpia at simpleng nagbibigay sa estado ng mga lugar na binabaha pati na rin ang isang pangheograpiyang endpoint na magbibigay sa mga lugar na binabaha na napapailalim sa isang minimum\_state o kung saan lahat ng mga lugar kasama ang kanilang kasalukuyang katayuan sa pagbaha. Bilang karagdagan sa [topojson ](https://github.com/topojson/topojson/wiki)at [geojson ](https://geojson.org/)sinusuportahan ng endpoint na ito ang[ Common Alerting Protocol (CAP)](https://en.wikipedia.org/wiki/Common_Alerting_Protocol).

Tandaan na ang mga estadong baha na nasa CAP format ay mayroong default na pag-expire sa loob ng 6 na oras simula sa kahilingan ng API.&#x20;

## State Codes ng Baha

Numeric codes are used to represent flood states, these are as follows:

| Code | Severity   | Description                                 |
| ---- | ---------- | ------------------------------------------- |
| 1    | Hindi Alam | HINDI ALAM ANG ANTAS NG BAHA -  MAG INGAT - |
| 2    | Minor      | BAHA SA PAGITAN NG 10 AT 70 SENTIMETRO      |
| 3    | Katamtaman | BAHA SA PAGITAN NG 71 AT 150 SENTIMETRO     |
| 4    | Marahas    | BAHA MAHIGIT 150 SENTIMETRO                 |

## Format ng Paghiling

| Query Parameter | Paglalarawan                                                                                                                | Format | Required |
| --------------- | --------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| city            | Aling lungsod ang nais naming ibalik ang mga imprastraktura? (isa sa`bdg`, `jbd`, `sby`)                                    | String | No       |
| format          | Aling format ang dapat nating ibalik ang mga resulta? (isa sa`json`, `xml`, defaults to `json`)                             | String | No       |
| geoformat       | Anong format ang dapat gamitin ang mga resulta sa heyograpiya? (isa sa `topojson`, `geojson`, `cap` defaults to `topojson`) | String | No       |
| minimum\_state  | Ang minimum na estado ng baha na dapat ibalilk? (min: `1`, max: `4`)                                                        | Number | No       |

## KUMUHA /floods

{% tabs %}
{% tab title="https" %}
Ilista ang lahat ng mga lugar na binabaha sa Quezon City na may estado ng baha (flood state) ng 1 o mas mataas.

```
curl "https://data.petabencana.id/floods?city=jbd&minimum_state=1"
```

{% endtab %}

{% tab title="https" %}
List all flooded areas in Jakarta with a flood state of 1 or higher in CAP format.

```
curl "https://data.petabencana.id/floods?city=jbd&minimum_state=1&format=xml&geoformat=cap"
```

{% endtab %}
{% endtabs %}

Ang mga resulta ay ang mga sumusunod:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "Topology",
    "objects": {
      "output": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Polygon",
            "properties": {
              "area_id": "5",
              "geom_id": "3174040004009000",
              "area_name": "RW 09",
              "parent_name": "GROGOL",
              "city_name": "Jakarta",
              "state": 1,
              "last_updated": "2016-12-19T13:53:52.274Z"
            },
            "arcs": [
              [
                0
              ]
            ]
          }
        ]
      }
    },
    "arcs": [
      [
        [
          9999,
          7847
        ],
        [
          -507,
          -6
        ],
        [
          -695,
          -70
        ],
        [
          -317,
          -221
        ],
        [
          -761,
          -18
        ],
        [
          -516,
          98
        ],
        [
          -641,
          -61
        ],
        [
          -649,
          -119
        ],
        [
          -169,
          -762
        ],
        [
          -181,
          -519
        ],
        [
          48,
          -602
        ],
        [
          -130,
          -162
        ],
        [
          64,
          -1235
        ],
        [
          81,
          -2351
        ],
        [
          136,
          -1098
        ],
        [
          15,
          -675
        ],
        [
          -1250,
          -40
        ],
        [
          -879,
          -6
        ],
        [
          -924,
          217
        ],
        [
          -924,
          425
        ],
        [
          -1800,
          138
        ],
        [
          830,
          1540
        ],
        [
          565,
          1455
        ],
        [
          764,
          1975
        ],
        [
          1018,
          2079
        ],
        [
          384,
          788
        ],
        [
          389,
          1061
        ],
        [
          1398,
          -76
        ],
        [
          296,
          -25
        ],
        [
          360,
          6
        ],
        [
          392,
          -9
        ],
        [
          360,
          -9
        ],
        [
          377,
          12
        ],
        [
          323,
          25
        ],
        [
          354,
          76
        ],
        [
          296,
          89
        ],
        [
          211,
          42
        ],
        [
          290,
          52
        ],
        [
          217,
          28
        ],
        [
          341,
          110
        ],
        [
          43,
          -67
        ],
        [
          57,
          -174
        ],
        [
          109,
          -159
        ],
        [
          154,
          -257
        ],
        [
          115,
          -370
        ],
        [
          99,
          -346
        ],
        [
          124,
          -357
        ],
        [
          133,
          -422
        ]
      ]
    ],
    "transform": {
      "scale": [
        0.0000003311331833192323,
        0.00000032713269326930546
      ],
      "translate": [
        106.7917869997,
        -6.158925
      ]
    },
    "bbox": [
      106.7917869997,
      -6.158925,
      106.7950980004,
      -6.1556540002
    ]
  }
}
```

Ang mga resulta ay ang mga sumusunod:

```markup
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>https://data.petabencana.id/floods</id>
    <title>petabencana.id Flood Affected Areas</title>
    <updated>2016-12-19T23:08:52+07:00</updated>
    <author>
        <name>petabencana.id</name>
        <uri>https://petabencana.id/</uri>
    </author>
    <entry>
        <id>https://data.petabencana.id/floods?parent_name=GROGOL&amp;area_name=RW%2009&amp;time=2016-12-19T22:41:35+07:00</id>
        <title>GROGOL.RW_09.2016-12-19T22:41:35+07:00 Flood Affected Area</title>
        <updated>2016-12-19T22:41:35+07:00</updated>
        <content type="text/xml">
            <alert xmlns="urn:oasis:names:tc:emergency:cap:1.2">
                <identifier>GROGOL.RW_09.2016-12-19T22:41:35+07:00</identifier>
                <sender>BPBD.JAKARTA.GOV.ID</sender>
                <sent>2016-12-19T22:41:35+07:00</sent>
                <status>Actual</status>
                <msgType>Alert</msgType>
                <scope>Public</scope>
                <info>
                    <category>Met</category>
                    <event>FLOODING</event>
                    <urgency>Immediate</urgency>
                    <severity>Minor</severity>
                    <certainty>Observed</certainty>
                    <senderName>JAKARTA EMERGENCY MANAGEMENT AGENCY</senderName>
                    <headline>FLOOD WARNING</headline>
                    <description>AT 22:41 WIB THE JAKARTA EMERGENCY MANAGEMENT AGENCY OBSERVED FLOODING OF BETWEEN 10 and 70 CENTIMETERS IN GROGOL, RW 09.</description>
                    <web>https://petabencana.id/</web>
                    <area>
                        <areaDesc>RW 09, GROGOL</areaDesc>
                        <polygon>-6.1563580003,106.7950980004 -6.1563600004,106.7949299998 -6.1563829997,106.7947 -6.1564550003,106.7945949997 -6.1564609997,106.7943429997 -6.156429,106.7941719999 -6.156449,106.7939600001 -6.156488,106.793745 -6.1567369998,106.7936890001 -6.1569070004,106.7936290001 -6.1571040005,106.7936449999 -6.1571570003,106.7936019997 -6.157561,106.7936229998 -6.1583300004,106.7936500001 -6.1586889999,106.7936950004 -6.1589100002,106.7936999998 -6.1589229999,106.7932860005 -6.158925,106.7929949996 -6.1588540003,106.7926889999 -6.1587150002,106.7923830002 -6.1586699999,106.7917869997 -6.158166,106.7920619998 -6.1576899997,106.7922490003 -6.1570440005,106.7925020003 -6.1563639997,106.7928389996 -6.1561060004,106.7929660001 -6.1557589997,106.7930949997 -6.1557839999,106.7935580004 -6.1557920003,106.7936560004 -6.1557900002,106.7937749996 -6.1557930003,106.7939050002 -6.1557960005,106.7940240003 -6.1557920003,106.7941489998 -6.1557839999,106.7942560002 -6.1557589997,106.7943730002 -6.1557300001,106.7944710002 -6.1557160004,106.7945409999 -6.1556990005,106.7946369998 -6.1556900001,106.7947090004 -6.1556540002,106.7948220002 -6.1556760003,106.794836 -6.1557330003,106.794855 -6.155785,106.7948909998 -6.1558690002,106.7949420004 -6.1559900004,106.7949800003 -6.1561030002,106.7950130001 -6.1562200002,106.7950540001 -6.1563580003,106.7950980004 </polygon>
                    </area>
                </info>
            </alert>
        </content>
    </entry>
</feed>
```

## KUMUHA /floods/states

Ilista ang lahat ng mga estadong binahang  ng nabahaang lugar sa Quezon City na may flood state.

```
curl "https://data.petabencana.id/floods/states?city=jbd&minimum_state=1"
```

Ang mga resulta ay ang mga sumusunod:

```javascript
{
  "statusCode": 200,
  "result": [
    {
      "area_id": "5",
      "state": 1,
      "last_updated": "2016-12-19T13:53:52.274Z"
    }
  ]
}
```

## ILAGAY /floods/:localAreaId

ILAGAY ang bagong flood state sa system para sa isang naituring lokal na lugar. ( PUT a new flood state in the system for a given local area (ligtas, nangangailangan ng token ng pahintulot).&#x20;

```
curl -X PUT -H "Content-Type: application/json" -d '{
    "state": 2
}' "https://data.petabencana.id/floods/5"
```

Ang mga resulta ay ang mga sumusunod:

```javascript
{
  "localAreaId": 5,
  "state": 2,
  "updated": true
}
```

## TANGGALIN /floods/:localAreaId

Inaalis ang kabuuang flood state para sa isang piling lokal na lugar. (ligtas, nangangailangan ng token ng pahintulot)

```
curl -X DELETE "https://data.petabencana.id/floods/5"
```

Ang mga resulta ay ang mga sumusunod:

```javascript
{
  "localAreaId": 5,
  "state": null,
  "updated": true
}
```


# Baha/Archive

Ang archive ng mga lugar na binabaha (tingnan ang dokumentasyon ng [Floods endpoint](/routes/floods)), na ipinakita bilang pinakamataas na flood state na naitala para sa lahat ng mga apektadong lugar sa baha sa loob na tinukoy na panahon. Ang maximum na estado ay naitala kasabay ng area id. Gamitin ang Floods endpoint upang makakuha ng mga hangganan ng geospatial ng mga bawat lugar.

Sa kasuluuyan ang datos na ito ay  magagamit lamang para sa Quezon City at Pampanga.

## Format ng Kahilingan

| Query Parameter | Paglalarawan                                    | Format                                              | Required |
| --------------- | ----------------------------------------------- | --------------------------------------------------- | -------- |
| start           | Oras ng pagsisimula para sa panahon ng archive. | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |
| end             | Pagtatapos ng oras para sa panahon ng archive   | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |

Tandaan na ang time zone ay dapat na tinukoy bilang +/- ang UTC na mangangailangan ng pag-encode ng character na HTML (hal. +0700 nagiging% 2B0700).

## Kumuha /floods/archive

## KUMUHA /floods

Ilista ang lahat ng mga lugar na binabaha sa Jakarta na may flood gauge ng 1 o mas mataas.

```
curl "https://data.petabencana.id/floods/archive?start=2017-06-07T00:00:00%2B0700&end=2017-06-08T23:00:00%2B0700"
```

Ang mga resulta ay ang mga sumusunod:

```javascript
    {
        "statusCode": 200,
        "result": [
            {
                "area_id": "509",
                "last_updated": "2017-11-03T22:57:01.387Z",
                "max_state": 1
            },
            {
                "area_id": "510",
                "last_updated": "2017-11-03T22:57:10.463Z",
                "max_state": 4
            }
        ]
    }
```


# Baha/Timeseries

Serye ng oras ng mga lugar na binabaha (tingnan ang dokumentasyon ng [Floods endpoint](/routes/floods)), na itinanghal bilang bilang ng mga lugar na apektado ng baha bawat oras sa loob ng tinukoy na panahon. Ang bilang ay naitala kasama ang isang oras-oras na timestamp sa format na ISO8601 sa UTC + 0.

Sa kasuluuyan ang datos na ito ay magagamit lamang para sa Quezon City at Pampanga.

## Format ng Kahilingan

| Query Parameter | Paglalarawan                                          | Format                                              | Required |
| --------------- | ----------------------------------------------------- | --------------------------------------------------- | -------- |
| start           | Oras ng pagsisimula para sa panahon ng serye ng oras. | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |
| end             | Oras ng pagtatapos para sa panahon ng serye ng oras   | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |

Tandaan na ang time zone ay dapat na tinukoy bilang +/- Ang offset ng UTC na mangangailangan ng pag-encode ng character na HTML (hal. +0700 nagiging% 2B0700).

## Kumuha /floods/timeseries

## KUMUHA /floods

Ilista ang lahat ng mga lugar na binabaha sa Quezon City at Pampanga na may flood gauge ng 1 o mas mataas

```
curl "https://data.petabencana.id/floods/timeseries?start=2017-11-20T11%3A00%3A00-0500&end=2017-11-20T15%3A00%3A00-0500"
```

Ang mga resulta ay ang mga sumusnod:

```javascript
    {
        "statusCode": 200,
        "result": [
            {
                "ts": "2017-11-20T16:00:00.000Z",
                "count": "0"
            },
            {
                "ts": "2017-11-20T17:00:00.000Z",
                "count": "0"
            },
            {
                "ts": "2017-11-20T18:00:00.000Z",
                "count": "0"
            },
            {
                "ts": "2017-11-20T19:00:00.000Z",
                "count": "0"
            },
            {
                "ts": "2017-11-20T20:00:00.000Z",
                "count": "0"
            }
        ]
    }
```


# Imprastraktura

Ang mga lokasyon ng lokal na imprastraktura kabilang ang mga flood gates, bomba at daanan ng tubig.

## Format ng Kahilingan

| URL Parameter | Paglalarawan                                                                                    | Format | Required |
| ------------- | ----------------------------------------------------------------------------------------------- | ------ | -------- |
| type          | Anong uri ng imprastraktura ang nais naming ilista?  (isa sa`floodgates`, `pumps`, `waterways`) | String | Yes      |

| Query Parameter | Paglalarawan                                                                                                                            | Format | Required |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| city            | Aling lungsod ang nais nating ibalik ang mga imprastraktura? (isa sa `bdg`, `jbd`, `sby`)                                               | String | No       |
| format          | Aling format ang dapat nating ibalik? (isa sa `json`, defaults to `json`)                                                               | String | No       |
| geoformat       | Anong format ang dapat gamitin ng geographic results o ang resulta sa heyograpiya (isa sa `topojson`, `geojson` defaults to `topojson`) | String | No       |

## KUMUHA /infrastructure/:type

Ibalik ang isang listahan ng mga bomba sa Quezon CIty at Pampanga.&#x20;

```
curl "https://data.petabencana.id/infrastructure/pumps?city=jbd"
```

Ang mga resulta ay ang mga sumusnod:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "Topology",
    "objects": {
      "output": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Point",
            "properties": {
              "name": "PA Marina"
            },
            "coordinates": [
              7164,
              7352,
              0
            ]
          },
          {
            "type": "Point",
            "properties": {
              "name": "Pompa Waduk Setia Budi Barat"
            },
            "coordinates": [
              5312,
              5077,
              0
            ]
          },
          // etc. etc. //
          {
            "type": "Point",
            "properties": {
              "name": "Pompa UP Senen"
            },
            "coordinates": [
              6143,
              6544,
              0
            ]
          }
        ]
      }
    },
    "arcs": [],
    "transform": {
      "scale": [
        0.000020651319451945148,
        0.000020217245084508508
      ],
      "translate": [
        106.7188310623,
        -6.3060956581
      ]
    },
    "bbox": [
      106.7188310623,
      -6.3060956581,
      106.9253236055,
      -6.1039434245
    ]
  }
}
```


# Ulat

Ang mga ulat tungkol sa live na kalamidad, sa pamamagitan ng default na mga ulat ay ibabalik sa huling oras.

## Format ng Kahilingan

| Query Parameter | Paglalarawan                                                                                                                                                                       | Format | Required |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| admin           | Aling lungsod ang nais nating ibalik ang mga imprastraktura? (isa sa [supported areas](https://github.com/petabencana/mapakalamidad-docs/blob/tagalog/general/supported-area.md) ) | String | No       |
| format          | Aling format ang dapat nating ibalik ang mga resulta? (isa sa `json`, defaults to `json`)                                                                                          | String | No       |
| geoformat       | Anong format ang dapat gamitin ang mga resulta sa heyograpiya? (isa sa `topojson`, `geojson` defaults to `topojson`)                                                               | String | No       |
| timeperiod      | Anong tagal ng panahon (sa mga segundo) upang ilista ang mga ulat para sa, mahigpit na karapat-dapat sa pagitan ng 1 at 604800 (1 linggo)                                          | Number | No       |

## KUMUHA /reports

Ilista ang lahat ng kasalukuyang ulat sa baha para sa Quezon City at Pampanga.

Note : Please include a User-Agent header in all of your requests. The User-Agent header helps us identify your requests and troubleshoot any issues you may have. To set the User-Agent header, add the following line to your request headers:

```
curl --user-agent "YOUR-UA-STRING" "https://api.mapakalamidad.ph/reports?admin=PH-00"
```

Ang mga resulta ay ang mga sumusnod:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "Topology",
    "objects": {
      "output": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Point",
            "properties": {
              "pkey": "5519",
              "created_at": "2016-12-09T21:37:00.000Z",
              "source": "qlue",
              "status": "confirmed",
              "url": null,
              "image_url": "https://lh3.googleusercontent.com/ByClSrW6QhFkBxUhZo0rFt6eiVdvnEHisSzsgjaC9KxdGAQ6CYksTZRA1rcNP9cBGZiv6s4Vp5D8NzkAjPyrBs6c6R4h=s480-c",
              "disaster_type": "flood",
              "report_data": null,
              "tags": {
                "instance_region_code": "jbd",
                "local_area_id": "350"
              },
              "title": " ",
              "text": "Perlu penataan dan dirapihkan @ahokbtp semoga bisa lbh baik, bersih dan teratur"
            },
            "coordinates": [
              0,
              0
            ]
          }
        ]
      }
    },
    "arcs": [],
    "transform": {
      "scale": [
        1,
        1
      ],
      "translate": [
        106.817276,
        -6.138229
      ]
    },
    "bbox": [
      106.817276,
      -6.138229,
      106.817276,
      -6.138229
    ]
  }
}
```


# Ulat/Archive

Archive ng mga ulat sa baha (tingnan ang Mga dokumentasyon ng [Reports endpoint](/routes/reports)), na ipinakita bilang isang JSON kasama ang lahat ng mga ulat sa pagbaha na natanggap sa loob ng tinukoy na tagal ng panahon.

Sa kasalukuyan ang mga datos na ito ay magagamit lamang para sa Quezon City at Pamapanga.

## Format ng Kahilingan

| Query Parameter | Paglalarawan                                                                                                                                                                       | Format                                              | Required |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | -------- |
| start           | Oras ng pagsisimula para sa panahon ng archive                                                                                                                                     | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |
| end             | Pagtatapos ng oras para sa panahon ng archive                                                                                                                                      | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |
| admin           | Aling lungsod ang nais nating ibalik ang mga imprastraktura? (isa sa [supported areas](https://github.com/petabencana/mapakalamidad-docs/blob/tagalog/general/supported-area.md) ) | String                                              | No       |
| geoformat       | Anong format ang dapat gamitin ang mga resulta sa heyograpiya? (isa sa `topojson`, `geojson` defaults to `topojson`)                                                               | String                                              | No       |

Tandaan na ang time zone ay dapat na tinukoy bilang +/- Ang offset ng UTC na mangangailangan ng pag-encode ng character na HTML (hal. +0700 nagiging% 2B0700).

## Kumuha/reports/archive

Note : Please include a User-Agent header in all of your requests. The User-Agent header helps us identify your requests and troubleshoot any issues you may have. To set the User-Agent header, add the following line to your request headers:

Ilista ang mga ulat sa pagbaha sa Quezon City at Pampanga na natanggap sa loob ng tinukoy na window ng oras:

```
curl --user-agent "YOUR-UA-STRING" "https://api.mapakalamidad.ph/reports/archive?start=2017-12-04T00%3A00%3A00%2B0700&end=2017-12-06T05%3A00%3A00%2B0700&geoformat=geojson"
```

Ang mga resulta ay ang mga sumusunod:

```javascript
{
    "statusCode": 200,
    "result": {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [
                        106.815842,
                        -6.183179
                    ]
                },
                "properties": {
                    "pkey": "0001",
                    "created_at": "2017-12-04T09:51:00.000Z",
                    "source": "qlue",
                    "status": "confirmed",
                    "url": null,
                    "image_url": null,
                    "disaster_type": "flood",
                    "report_data": null,
                    "tags": {
                        "instance_region_code": "jbd",
                        "local_area_id": "782"
                    },
                    "title": " ",
                    "text": "#flood report"
                }
            }
          ]
        }
      }
```


# Reports/Timeseries

Time series of flood reports (see [Reports endpoint](/routes/reports) documentation), presented as the count of flood reports every hour within the specified time period. Count is recorded alongside an hourly timestamp in ISO8601 format at UTC+0.

## Request Format

| Query Parameter | Description                      | Format                                              | Required |
| --------------- | -------------------------------- | --------------------------------------------------- | -------- |
| start           | Start time for timeseries period | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |
| end             | End time for timeseries period   | String in ISO 8601 format (YYYY-MM-DDTHH:mm:ss+ZZZZ | Yes      |

Note that time zone must be specified as +/- UTC offset which will require HTML character encoding (e.g. +0700 becomes %2B0700).

## Get /reports/timeseries

## GET /reports/timeseries

Get count of flood reports within specified time period.

```
    curl "https://data.petabencana.id/reports/timeseries?start=2017-11-26T12%3A00%3A00%2B0700&end=2017-11-26T15%3A00%3A00%2B0700"
```

Results are as follows:

```javascript
    {
        "statusCode": 200,
        "result": [
            {
                "ts": "2017-11-26T05:00:00.000Z",
                "count": "0"
            },
            {
                "ts": "2017-11-26T06:00:00.000Z",
                "count": "0"
            },
            {
                "ts": "2017-11-26T07:00:00.000Z",
                "count": "2"
            },
            {
                "ts": "2017-11-26T08:00:00.000Z",
                "count": "3"
            }
        ]
    }
```


# Stats

Some summary statistics:

* [/stats/floodedRegionsSummary](/routes/stats/floodedregionssummary) :  summary of regions containing flooded RWs
* [/stats/floodedRWsSummary](/routes/stats/floodedrwssummary) : summary of flooded RWs
* [/stats/reportsSummary](/routes/stats/reportssummary) : summary of reports


# Stats - Reports Summary

Count of reports by source ("qlue" for Qlue, "detik" for Detik Pasangmata, or "grasp" being combined Twitter and Telegram), by default reports will be returned for the last hour.

## Request Format

| Query Parameter | Description                                                                                       | Format | Required |
| --------------- | ------------------------------------------------------------------------------------------------- | ------ | -------- |
| city            | Which city do we wish to return infrastructure for? (one of `bdg`, `jbd`, `sby`)                  | String | No       |
| timeperiod      | What time period (in seconds) to list reports for, must be strictly between 1 and 604800 (1 week) | Number | No       |

## GET /stats/getReportsSummary.md

```
curl "https://data.petabencana.id/stats/reportsSummary?city=jbd"
```

Results are as follows:

```javascript
{
  "statusCode": 200,
  "result": {
    "type": "Topology",
    "objects": {
      "output": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Point",
            "properties": {
              "pkey": "5519",
              "created_at": "2016-12-09T21:37:00.000Z",
              "source": "qlue",
              "status": "confirmed",
              "url": null,
              "image_url": "https://lh3.googleusercontent.com/ByClSrW6QhFkBxUhZo0rFt6eiVdvnEHisSzsgjaC9KxdGAQ6CYksTZRA1rcNP9cBGZiv6s4Vp5D8NzkAjPyrBs6c6R4h=s480-c",
              "disaster_type": "flood",
              "report_data": null,
              "tags": {
                "instance_region_code": "jbd",
                "local_area_id": "350"
              },
              "title": " ",
              "text": "Perlu penataan dan dirapihkan @ahokbtp semoga bisa lbh baik, bersih dan teratur"
            },
            "coordinates": [
              0,
              0
            ]
          }
        ]
      }
    },
    "arcs": [],
    "transform": {
      "scale": [
        1,
        1
      ],
      "translate": [
        106.817276,
        -6.138229
      ]
    },
    "bbox": [
      106.817276,
      -6.138229,
      106.817276,
      -6.138229
    ]
  }
}
```


# Stats - Flooded RWs Summary

Count of all RWs by flood height range.

## Request Format

| Query Parameter | Description                                                                      | Format | Required |
| --------------- | -------------------------------------------------------------------------------- | ------ | -------- |
| city            | Which city do we wish to return infrastructure for? (one of `bdg`, `jbd`, `sby`) | String | No       |

## GET /stats/floodedRWsSummary

```
curl "https://data.petabencana.id/stats/floodedRWsSummary?city=jbd"
```

Results are as follows:

```javascript
{
  "# hati-hati RWs": 0,
  "# 10-70cm RWs": 9,
  "# 71-150cm RWs": 0,
  "# 151cm+ RWs": 0
}
```


# Stats - Flooded Regions Summary

List of all regions with currently flooded RWs.

## Request Format

| Query Parameter | Description                                                                      | Format | Required |
| --------------- | -------------------------------------------------------------------------------- | ------ | -------- |
| city            | Which city do we wish to return infrastructure for? (one of `bdg`, `jbd`, `sby`) | String | No       |

## GET /stats/floodedRegionsSummary

```
curl "https://data.petabencana.id/stats/floodedRegionsSummary?city=jbd"
```

Results are as follows:

```javascript
{
  "total number of regions with flooded RWs": 4,
  "regions with flooded RWs": [
    "KAPUK",
    "RAWA TERATE",
    "CIPINANG MELAYU",
    "CENGKARENG BARAT"
  ]
}
```


