amadeus4dev / amadeus-java

Java library for the Amadeus Self-Service travel APIs
https://developers.amadeus.com/
MIT License
87 stars 69 forks source link

The access token provided in the Authorization header is invalid #247

Closed Treasureworth closed 1 year ago

Treasureworth commented 1 year ago

Description

I followed through the initialisation step for Amadeus Java SDK but I am getting "Invalid access token" with "The access token provided in the Authorization header is invalid" as the error detail.

Steps to Reproduce

  1. I set the following environment variables AMADEUS_CLIENT_ID and AMADEUS_CLIENT_SECRET
  2. Amadeus amadeus = Amadeus.builder(System.getenv()) .setLogLevel("debug") .build();
  3. I called amadues.referenceData.airlines.get();

Expected Behavior: I expected to get Airline[] as the response.

Actual Behavior: The Log showed that a token was created but when call is made to https://travel.api.amadeus.com:443/v1/reference-data/airlines it returned an error that says that The access token provided in the Authorization header is invalid

Stable Behavior? This happens every of the time I tried to run my application.

Versions

com.amadeus amadeus-java 7.0.0

[What version of Java/JVM are you running? What Operating System are you on?] Java 17. Mac OS Monterey Version 12.6

tsolakoua commented 1 year ago

Amadeus for Developers Self-Service APIs and the SDKs target to the followings URLs:

The endpoint you provide https://travel.api.amadeus.com/v1/reference-data/airlines doesn't look like a Self-Service one.

Here is a full example for the API you try to call.

import com.amadeus.Amadeus;
import com.amadeus.Params;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.Airline;

public class Search {

  public static void main(String[] args) throws ResponseException {

    Amadeus amadeus = Amadeus
        .builder("YOUR_API_KEY","YOUR_API_SECRET")
        .build();

    Airline[] airlines = amadeus.referenceData.airlines.get(Params
      .with("airlineCodes", "BA"));

    if (airlines[0].getResponse().getStatusCode() != 200) {
        System.out.println("Wrong status code: " + airlines[0].getResponse().getStatusCode());
        System.exit(-1);
    }

    System.out.println(airlines[0]);
  }
}