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);
}
1

There are 1 best solutions below

2
Throvn On

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
})