Flutter Dev
Flutter Dev

Reputation: 568

When making a request to the Vision API Product Search an error occurs "message": "The request is missing a valid API key."

When I register a service account for the Vision API Product Search there's a json file downloaded into my desktop that has the private key. However, when making a request into this api there's no place to send that JSON. I'll show you the documentation and my code. I didn't understand also what is the curl request and how to send it using the http post request. Documentation Image

And This is my code:

Future<void> uploadProductSet() async {
    var projectId = 'estoOne';
    var locationId = 'europe-west1';
    var url = 'https://vision.googleapis.com/v1/projects/$projectId/locations/$locationId/productSets';

    final responseOne = await http
        .post(Uri.parse(url),
            body: json.encode({
                'displayName': 'Product-Set-One',
            }))
        .catchError((error) {
            throw error;
    });
    print(resoinseOne.body);
}

Upvotes: 0

Views: 212

Answers (1)

Throvn
Throvn

Reputation: 971

You have to send your access token with the Authorization header. The API seems to use the Bearer authentication method.

So set the following header in your http request: Bearer $authToken You should get the auth-token from the credentials file you've downloaded

So your code should look something like this: (untested)

await http.post(Uri.parse(url), 
    headers: { 'Authorization': 'Bearer $authToken' },
    body: json.encode({
        'displayName': 'Product-Set-One',
})).catchError((error) {
    throw error
})

Upvotes: 1

Related Questions