I'm setting up a server, and I need to use the Google speech API in order to translate an audio to a text. This server send a post request to Google's API and retrieve the NAME(ID) of the operation. Then I'm trying to make a get request with tihs NAME(ID) to retrieve the data, but I'm getting a 404 error.
I've already tryied to use api.get('/v1p1beta1/operations/{NAME}') with my API KEY from Google like this api.get('/v1p1beta1/operations/{NAME}?key={key}') but then I got a bad request. Also this code worked, but stopped and I don't know why.
const api = await axios.create({
baseURL: 'https://speech.googleapis.com',
crossDomain: true,
responseType: 'json',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': "Bearer <<TOKEN>>"
},
});
// calling api
api.get('/v1p1beta1/operations/{NAME}')
.then(resp=>{
console.log( resp);
}).
catch('error');
})
I found out the problem, it was when I return the NAME(ID) from the server, It was rounded and then when I called the GET function the ID didn't match. What I did was stringfy the value, and it solved the problem.
return JSON.stringify(result.data.name);