citiesByCountry
Overview
Fetch the list of cities that belong to a specific country.
- Type: GraphQL Query
- Endpoint: https://subdomain.com
- Authentication:
Authorization: Bearer <TOKEN>
Query
query FindAllCitiesByCountry($countryId: ID!) {
findAllCitiesByCountry(countryId: $countryId) {
success
message
data {
_id
name
description
active
deleted
country {
_id
name
image { image imageUrl }
code
continent
capital
active
deleted
phonekey
createdAt
updatedAt
}
}
}
}
Variables
{
"countryId": "<COUNTRY_ID>"
}
Examples
- cURL
- JavaScript (fetch)
curl -X POST \
https://subdomain.com\
-H "Content-Type: application/json" \
-H "Authorization: Bearer <TOKEN>" \
--data-binary @- << 'EOF'
{
"query": "query FindAllCitiesByCountry($countryId: ID!) { findAllCitiesByCountry(countryId: $countryId) { success message data { _id name } } }",
"variables": { "countryId": "<COUNTRY_ID>" }
}
EOF
const res = await fetch('https://subdomain.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
body: JSON.stringify({
query: `
query FindAllCitiesByCountry($countryId: ID!) {
findAllCitiesByCountry(countryId: $countryId) {
success
message
data { _id name }
}
}
`,
variables: { countryId: COUNTRY_ID },
}),
});
const json = await res.json();
Notes
- Replace
<TOKEN>and<COUNTRY_ID>with valid values. - You can expand the selected fields under
dataas needed (e.g.,description,active).