JohnnyQ
JohnnyQ

Reputation: 543

Future Call return API key invalid error UNAUTHORIZED

I'm trying to access an API endpoint using a Future and it constantly returns:

{"code":"UNAUTHORIZED","message":"Invalid API Key","timestamp":"2022-03-19T16:57:02.300792Z","trackingId":"4E98D1A6:9539_0A5D03B2:01BB_62360B5E_7DAF37:3959"}

I know the reason why it failed is obvious in the error message but I don't know where where my call is going wrong.

I'm using the correct API key

  Future<void> getThingsToDo() async {
var headers = {
  'exp-api-key': '*******-**My-API*-*KEY-************',
  'Accept-Language': 'en-US',
  'Accept': 'application/json;version=2.0',
};

try {
  var url = Uri.parse(
      'https://api.sandbox.viator.com/partner/products/5010SYDNEY');

  var response = await http.get(url, headers: headers);

  if (response.statusCode == 200) {
    var jsonData = json.decode(response.body);
    print('Call Worked');

    return jsonData;
  } else {
    print(response.statusCode);
    print(response.body);
  }
} catch (e) {
  print(e);
}
throw Exception(' There is something wrong');
}

These are the sample instructions:

enter image description here

enter image description here

Upvotes: 2

Views: 516

Answers (1)

JohnnyQ
JohnnyQ

Reputation: 543

Foe anyone using the Viatour api unless you are a merchant don't use the sandbox version.

var url = Uri.parse(
      'https://api.sandbox.viator.com/partner/products/5010SYDNEY');

to

var url = Uri.parse(
      'https://api.viator.com/partner/products/5010SYDNEY');

Upvotes: 1

Related Questions