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
5628
1210
5628
  • 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. No results when querying Subdivisions_States_Provinces

New IssueNew

paul commented this issue on Apr 2020

I've used the example code to try and query the Subdivisions_States_Provinces endpoint for results within a specific country code and used a couple of country codes to test, but nothing is returned.

Any assistance would be greatly appreciated.

Regards, Paul

paul commented this issue on Apr 2020

The same happens when querying the cities endpoint.

I am using the javascript examples

davimacedo commented this issue on Apr 2020

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

{
  "results": [
    {
      "objectId": "BXkZTl2omc",
      "code": "US",
      "name": "United States",
      "native": "United States",
      "phone": "1",
      "continent": {
        "__type": "Pointer",
        "className": "Continent",
        "objectId": "vZNZcahFvu"
      },
      "capital": "Washington D.C.",
      "currency": "USD,USN,USS",
      "emoji": "🇺🇸",
      "emojiU": "U+1F1FA U+1F1F8",
      "createdAt": "2019-12-11T08:14:17.654Z",
      "updatedAt": "2020-04-13T18:19:25.532Z",
      "geonameid": 6252001,
      "shape": {
        "__type": "Pointer",
        "className": "Shape",
        "objectId": "sb3piMeMV9"
      },
      "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, searching for US cities, would require you to use the following request:

(async () => {
        const where = encodeURIComponent(JSON.stringify({
          "country": {
            "__type": "Pointer",
            "className": "Country",
            "objectId": "BXkZTl2omc"
          }
        }));
        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));
      })();
paul commented this issue on Apr 2020

Thanks for the advice @davimacedo. I also realised that there's an issue with the endpoint names in the generated code. The one for countries is correct, but the one for subdivisions is not 'Subdivisions_States_Provinces', it's 'Continentscountriescities_Subdivisions_States_Provinces' and the one for cities is not 'City', it's 'Continentscountriescities_City'. Having got that right, and with your advice, I got it all working.

Closed Issuepaul closed this issue on Apr 2020
davimacedo commented this issue on Apr 2020

I am glad you figured it out. When talking about the endpoint names, please note that they change wether you are using the fake app or your own app. I mean, if you select one of your apps in the step 1 of the get started, it should generate the code with the right names.

Please enter a comment for this issue.