meilisearch / meilisearch-rust

Rust wrapper for the Meilisearch API.

Home Page:https://www.meilisearch.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The X-MEILI-API-KEY header is missing. Please update the SDK

Zzaniu opened this issue · comments

use meilisearch_sdk::client::*;
use serde::{Serialize, Deserialize};
use futures::executor::block_on;

#[derive(Serialize, Deserialize, Debug)]
struct Movie {
    id: usize,
    title: String,
    genres: Vec<String>,
}


fn main() { 
    block_on(async move {
      let client = Client::new("http://localhost:7700", Some("aSampleMasterKey"));
  
      // An index is where the documents are stored.
      let movies = client.index("movies");
  
      // Add some movies in the index. If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
      movies.add_documents(&[
          Movie { id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()] },
          Movie { id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()] },
          Movie { id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()] },
          Movie { id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()] },
          Movie { id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()] },
          Movie { id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()] },
      ], Some("id")).await.unwrap();
  })
}

error:

called `Result::unwrap()` on an `Err` value: Meilisearch(MeilisearchError { error_message: "The X-MEILI-API-KEY header is missing.", error_code: MissingAuthorizationHeader, error_type: Auth, error_link: "https://docs.meilisearch.com/errors#missing_authorization_header" })

Hello @Zzaniu
The SDK is already update to use the latest authentication required by Meilisearch.

Which version of Meilisearch do you use? Which version of meilisearch-rust do you use?

We don't use X-Meili-API-key for almost 2 years

https://www.meilisearch.com/docs/reference/api/overview#authorization