title: Real time database REST API Constraint index field must be a JSON primitive
body: <p>I'm trying to make a query to the Real-time database from google using their rest API.
  this is how the data of &quot;waiters&quot; path looks like :</p>
  <pre><code>{
       &quot;-Kb2dYPV0yUXpD_1moc9&quot;: {
       &quot;id&quot;: &quot;Ky7gTz0BFyRudih0DhSAe3lwci13&quot;,
       &quot;role&quot;: &quot;normal&quot;  
       },  
  
       &quot;-Kb2etFm1xHd8sSsESeK&quot;: {
       &quot;id&quot;: &quot;VRBNr5OnMQaDoLpkKppapyDW8JZ2&quot;,
       &quot;role&quot;: &quot;admin&quot;
       },
   }
  </code></pre>
  <p>On the client-side, I know the id and what I would like to get is the role (i.e &quot;admin&quot; or whatever it is) but I don't know the autogenerated location-id (&quot;-Kb2etFm1xHd8sSsESeK&quot;).
  Does someone know how to proceed?</p>
  <p>I tried :</p>
  <pre><code>static Future&lt;RoleType&gt; fetchRole(String userId, String token) async {
  try {
    var url =
        &quot;https://xxx.firebaseio.com/waiters.json?orderBy=\&quot;id\&quot;&amp;equalTo=\&quot;&quot; +
            &quot;$userId\&quot;&quot; +
            &quot;?auth=&quot; +
            token;
    final response = await http.get(url);
    final extractedData = json.decode(response.body);
    
    if (extractedData == null) return null;
    return RoleType(extractedData['role']);
  } catch (error) {
    print(&quot;[fetchRole]:: &quot; + error.toString());
    throw error;
  }
  </code></pre>
  <p>}</p>
  <p>the URL without the token gives :</p>
  <pre><code>https://xxx.firebaseio.com/waiters.json? 
  orderBy=&quot;id&quot;&amp;equalTo=&quot;VRBNr5OnMQaDoLpkKppapyDW8JZ2&quot;?auth=token
  </code></pre>
  <p>But I get this error :
  {error: Constraint index field must be a JSON primitive}</p>
  <p>I still get this error when I update the rules as follow:</p>
  <pre><code>{
  &quot;rules&quot;: {
      &quot;.read&quot;: &quot;auth != null&quot;,  // 2020-11-9
      &quot;.write&quot;: &quot;auth != null&quot;,  // 2020-11-9
      &quot;waiters&quot;: {
            &quot;.indexOn&quot;: [&quot;id&quot;]
      }
    }
  }
  </code></pre>
  <p>Thanks in advance for your help!</p>