#community-help

Trouble Spotting API Error in Dart vs Shell Operations

TLDR Erick is having issues with the typesense API, receiving errors in Dart that are not present in shell operations. Despite Kishore Nallan trying to help, no solution has been found, leading Erick to post the issue on the dart client repository.

Powered by Struct AI
Feb 01, 2022 (20 months ago)
Erick
Photo of md5-5d002d197dc556e6bc619deaa3a8aba7
Erick
02:37 PM
Hi. I'm getting this error: "400: {"message": "Field value should be a string or a string array."}".
value specs:
{
"facet": false,
"index": true,
"name": "value",
"optional": false,
"type": "float"
},
02:37
Erick
02:37 PM
I'm using version 0.22.1
02:39
Erick
02:39 PM
Also, I keep getting this error too:

401: {"message": "Forbidden - a valid x-typesense-api-key header must be sent."}
02:42
Erick
02:42 PM
Kishore Nallan
03:10
Erick
03:10 PM
What is interesting is that performing the search with shell works but Dart doesn't
03:11
Erick
03:11 PM
I don't even get "400 Field should be string..." error.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:11 PM
Can you please create an exact code snippet that reproduces the error consistently?
Erick
Photo of md5-5d002d197dc556e6bc619deaa3a8aba7
Erick
03:13 PM
I'm using all 3 keys (Admin Key, Search-only Key and Tenant Key (created using filter_by and Search-only ket))
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:14 PM
Without the exact reproduceable code snippet, difficult to identify what's going wrong...
Erick
Photo of md5-5d002d197dc556e6bc619deaa3a8aba7
Erick
03:14 PM
await client!.collection(collection).documents.search({
  "q": value ?? "*",
  "query_by": queryBy,
});

Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:16 PM
I mean a fully reproduceable example with the client initialization as well. I recommend starting fresh on a new file so that if there was any mistake you can quickly identify it.
Erick
Photo of md5-5d002d197dc556e6bc619deaa3a8aba7
Erick
03:16 PM
oh
03:19
Erick
03:19 PM
Typesense Service

class SearchService {
Client? client;
String searchOne = "add-endpoint-here";
String searchTwo = "add-endpoint-here";
String searchThree = "add-endpoint-here";

void initialize(String searchKey) {
    var config = Configuration(
      searchKey,
      nodes: {
        Node(Protocol.https, searchOne, port: 443),
        Node(Protocol.https, searchTwo, port: 443),
        Node(Protocol.https, searchThree, port: 443),
      },
      connectionTimeout: Duration(seconds: 2),
    );
    client = Client(config);
}

  Future<dynamic> Search(
    String? value,
    String queryBy,
    String collection,
  ) async {
    try {
      var search = await client!.collection(collection).documents.search({
        "q": value ?? "*",
        "query_by": queryBy,
      });
         return search;
        } catch(err){
          return err;
        }
}
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:24 PM
That looks fine to me. And the problem occurs only with the scoped API key?
Erick
Photo of md5-5d002d197dc556e6bc619deaa3a8aba7
Erick
03:29 PM
scoped API key = error
Search-only key = error
Admin key = error
03:30
Erick
03:30 PM
Either "400 Field..." or "404 Forbidden..."
03:30
Erick
03:30 PM
Using shell everything works.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:30 PM
Hmm 🤔 Have you tried running the official client example? https://github.com/typesense/typesense-dart/tree/master/example/console-simple
Erick
Photo of md5-5d002d197dc556e6bc619deaa3a8aba7
Erick
03:35 PM
I was following the example code on pub.dev
03:36
Erick
03:36 PM
Our backend config is working without any issues. Any query from shell is working.
03:44
Erick
03:44 PM
There's something when logging Configuration object.
03:44
Erick
03:44 PM
I'm getting "Send api key in query: false"
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:45 PM
Can you summarize the problem you are facing and post on the dart client repository here? https://github.com/typesense/typesense-dart/issues
Erick
Photo of md5-5d002d197dc556e6bc619deaa3a8aba7
Erick
03:45 PM
No problem.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:45 PM
I will request one of the dart client maintainers to take a look. Since I'm unable to spot anything grossly wrong, maybe another pair of eyes will help.
Erick
Photo of md5-5d002d197dc556e6bc619deaa3a8aba7
Erick
03:46 PM
👍🏾
04:04
Erick
04:04 PM
Done.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
04:04 PM
:ty: