Use the code samples below to integrate your applications with the API.
This example uses the Axios HTTP client.
The following example demonstrates how to submit a JSON transcript for sentiment analysis using the Axios HTTP client.
To use this example, set the <REVAI_ACCESS_TOKEN> placeholder to your Rev AI account's access token.
const axios = require('axios');
const token = '<REVAI_ACCESS_TOKEN>';
// create a client
const http = axios.create({
baseURL: 'https://api.rev.ai/sentiment_analysis/v1/',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
// submit a POST request
const submitSentimentAnalysisJobJson = async (jsonData) => {
return await http.post(`jobs`,
JSON.stringify({
json: jsonData
}))
.then(response => response.data)
.catch(console.error);
};This example uses the Axios HTTP client.
The following example demonstrates how to submit a plaintext transcript for sentiment analysis using the Axios HTTP client.
To use this example, set the <REVAI_ACCESS_TOKEN> placeholder to your Rev AI account's access token.
const axios = require('axios');
const token = '<REVAI_ACCESS_TOKEN>';
// create a client
const http = axios.create({
baseURL: 'https://api.rev.ai/sentiment_analysis/v1/',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
// submit a POST request
const submitSentimentAnalysisJobText = async (textData) => {
return await http.post(`jobs`,
JSON.stringify({
text: textData
}))
.then(response => response.data)
.catch(console.error);
};This example uses the Axios HTTP client.
The following example demonstrates how to retrieve the status of a sentiment analysis job using the Axios HTTP client.
To use this example, set the <REVAI_ACCESS_TOKEN> placeholder to your Rev AI account's access token.
const axios = require('axios');
const token = '<REVAI_ACCESS_TOKEN>';
// create a client
const http = axios.create({
baseURL: 'https://api.rev.ai/sentiment_analysis/v1/',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
// submit a GET request
const getSentimentAnalysisJobStatus = async (jobId) => {
return await http.get(`jobs/${jobId}`)
.then(response => response.data)
.catch(console.error);
};This example uses the Axios HTTP client.
The following example demonstrates how to retrieve the result of a sentiment analysis job using the Axios HTTP client.
To use this example, set the <REVAI_ACCESS_TOKEN> placeholder to your Rev AI account's access token.
const axios = require('axios');
const token = '<REVAI_ACCESS_TOKEN>';
// create a client
const http = axios.create({
baseURL: 'https://api.rev.ai/sentiment_analysis/v1/',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
// submit a GET request
const getSentimentAnalysisJobResult = async (jobId) => {
return await http.get(`jobs/${jobId}/result`,
{ headers: { 'Accept': 'application/vnd.rev.sentiment.v1.0+json' } })
.then(response => response.data)
.catch(console.error);
};