# Cities

## List cities

<mark style="color:green;">`POST`</mark> `https://sandbox.mnasati.com/v1/cities`

This endpoint allows you to list all cities of a specific country.

#### Headers

| Name         | Type   | Description                                           |
| ------------ | ------ | ----------------------------------------------------- |
| Content-Type | string | Application/JSON                                      |
| Access Token | string | The JWT key generated using the Authorization method. |

#### Request Body

| Name        | Type    | Description                  |
| ----------- | ------- | ---------------------------- |
| country\_id | integer | The ID number of the country |

{% tabs %}
{% tab title="200 Cake successfully retrieved." %}

```
{
   "status":true,
   "data":[
      {
         "city_id":"1",
         "country_id":"1",
         "name":"Kuwait City",
         "name_ar":"العاصمة",
         "latitude":"29.375606",
         "longitude":"47.977318",
         "status":"1"
      },
      {
         "city_id":"99",
         "country_id":"16",
         "name":"city2",
         "name_ar":"city2",
         "latitude":null,
         "longitude":null,
         "status":"1"
      },
      {
         "city_id":"100",
         "country_id":"16",
         "name":"city3",
         "name_ar":"city3",
         "latitude":null,
         "longitude":null,
         "status":"1"
      }
   ]
}
```

{% endtab %}

{% tab title="400 " %}

```
{"status":400,"error":400,"messages":{"status":false,"message":"Access denied"}}
```

{% endtab %}
{% endtabs %}

## Examples

{% tabs %}
{% tab title="Python" %}

```python
import requests

url = "https://sandbox.mnasaticom/v1/cities"

payload = "{\"country_id\":1}"
headers = {
    'Content-Type': "",
    'Authorization-Jwt': ""
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://sandbox.mnasati.com/v1/cities",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"country_id\":1}",
  CURLOPT_HTTPHEADER => [
    "Authorization-Jwt: ",
    "Content-Type: "
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

{% endtab %}

{% tab title="Java" %}

```java
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"country_id\":1}");
Request request = new Request.Builder()
  .url("https://sandbox.mnasati.com/v1/cities")
  .post(body)
  .addHeader("Content-Type", "")
  .addHeader("Authorization-Jwt", "")
  .build();

Response response = client.newCall(request).execute();
```

{% endtab %}

{% tab title="C#" %}

```csharp
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://sandbox.mnasati.com/v1/cities"),
    Headers =
    {
        { "Content-Type", "" },
        { "Authorization-Jwt", "" },
    },
    Content = new StringContent("{\"country_id\":1}")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://sandbox.mnasati.com/v1/cities")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["Content-Type"] = ''
request["Authorization-Jwt"] = ''
request.body = "{\"country_id\":1}"

response = http.request(request)
puts response.read_body
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://sandbox.mnasati.com/v1/cities"

	payload := strings.NewReader("{\"country_id\":1}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "")
	req.Header.Add("Authorization-Jwt", "")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

{% endtab %}

{% tab title="Swift" %}

```swift
import Foundation

let headers = [
  "Content-Type": "",
  "Authorization-Jwt": ""
]
let parameters = ["country_id": 1] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.mnasati.com/v1/cities")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

{% endtab %}

{% tab title="jQuery" %}

```javascript
const settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://sandbox.mnasati.com/v1/cities",
  "method": "POST",
  "headers": {
    "Content-Type": "",
    "Authorization-Jwt": ""
  },
  "processData": false,
  "data": "{\"country_id\":1}"
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
```

{% endtab %}
{% endtabs %}
