0

I am trying to make a spacetraders.io client and when I try to send the token to the endpoint, I get a message saying that I did not send a token.
Relevant code:

let client = reqwest::Client::new();
let endpoint = "my/agent";
let res = client.get(format!("https://api.spacetraders.io/v2/{}", endpoint))
            .form(&data)
            .header("Authorization", format!("Bearer {}", token))
            .send()
            .await
            .unwrap();

1 Answers1

0

It's hard to answer this - this question isn't including enough code to really understand what might not be working.

Here is some working rust code to do what you're trying to do - you can compare this to your example to see where you might be going wrong.

use std::env;
use reqwest;

#[tokio::main]
async fn main() {
    //get SPACETRADERS_TOKEN from an environment variable
    let token = env::var("SPACETRADERS_TOKEN").is_ok();
    let client = reqwest::Client::new();
    let endpoint = "my/agent";
    let res = client.get(format!("https://api.spacetraders.io/v2/{}", endpoint))
                .header("Authorization", format!("Bearer {}", token))
                .send()
                .await
                .unwrap();
    println!("{:?}", res)
}