The Database Hub | Back4App
The Database Hub | Back4App
How it works
  • Log In
  • Sign Up

  1. Back4App
  2. World Continents, Countries, and Cities
Public

1210
6436
1210
  • DatabaseDatabase
  • GraphQL API PlaygroundAPI Playground
  • Get Started GuideGet Started
  • IssuesIssues
  • ContributorsContributors
  • Database
    Database
    GraphQL API Playground
    API Playground
    Get Started Guide
    Get Started
    Contributors
    Contributors

  1. Closed IssueClosed
  2. Internal server error

New IssueNew

medo.kamal40 commented this issue on Apr 2020

when i'm trying to request the states for specific country it returns this error 500 Internal server error

davimacedo commented this issue on Apr 2020

You have to use the country object id (and not the name). For example, if you search for China, you will see this response:

{
  "results": [
    {
      "objectId": "jPsWdF78Gn",
      "code": "CN",
      "name": "China",
      "native": "中国",
      "phone": "86",
      "continent": {
        "__type": "Pointer",
        "className": "Continent",
        "objectId": "mSxk54vkg6"
      },
      "capital": "Beijing",
      "currency": "CNY",
      "emoji": "🇨🇳",
      "emojiU": "U+1F1E8 U+1F1F3",
      "createdAt": "2019-12-09T21:27:25.283Z",
      "updatedAt": "2020-04-13T18:17:24.023Z",
      "geonameid": 1814991,
      "shape": {
        "__type": "Pointer",
        "className": "Shape",
        "objectId": "PpZLJvCZ04"
      },
      "languages": {
        "__type": "Relation",
        "className": "Language"
      },
      "cities": {
        "__type": "Relation",
        "className": "City"
      },
      "timezones": {
        "__type": "Relation",
        "className": "Timezone_Time_Zones_Dataset"
      },
      "provinces": {
        "__type": "Relation",
        "className": "Subdivisions_States_Provinces"
      }
    }
  ]
}

So, in order to query for China's cities, you would need to use the following request:

<html>
  <head></head>
  <body>
    <script type="text/javascript">
      (async () => {
        const where = encodeURIComponent(JSON.stringify({
          "country": {
            "__type": "Pointer",
            "className": "Country",
            "objectId": "jPsWdF78Gn"
          }
        }));
        const response = await fetch(
          `https://parseapi.back4app.com/classes/City?limit=10&where=${where}`,
          {
            headers: {
              'X-Parse-Application-Id': 'mxsebv4KoWIGkRntXwyzg6c6DhKWQuit8Ry9sHja', // This is the fake app's application id
              'X-Parse-Master-Key': 'TpO0j3lG2PmEVMXlKYQACoOXKQrL3lwM0HwR9dbH', // This is the fake app's readonly master key
            }
          }
        );
        const data = await response.json(); // Here you have the data that you need
        console.log(JSON.stringify(data, null, 2));
      })();
    </script>
  </body>
</html>
Closed Issuegeorge closed this issue on Jun 2020
Please enter a comment for this issue.