Code Samples

Use the code samples below to integrate your applications with the API.

Node

Submit JSON data for topic extraction

attention

This example uses the Axios HTTP client.

The following example demonstrates how to submit a JSON transcript for topic extraction using the Axios HTTP client.

To use this example, set the <REVAI_ACCESS_TOKEN> variable to your Rev AI account's access token.

Copy
Copied
const axios = require('axios');
const token = '<REVAI_ACCESS_TOKEN>';

// create a client
const http = axios.create({
  baseURL: 'https://api.rev.ai/topic_extraction/v1/',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
});

// submit a POST request
const submitTopicExtractionJobJson = async (jsonData) => {
  return await http.post(`jobs`,
    JSON.stringify({
      json: jsonData
    }))
    .then(response => response.data)
    .catch(console.error);
};

Submit plaintext data for topic extraction

attention

This example uses the Axios HTTP client.

The following example demonstrates how to submit a plaintext transcript for topic extraction using the Axios HTTP client.

To use this example, set the <REVAI_ACCESS_TOKEN> variable to your Rev AI account's access token.

Copy
Copied
const axios = require('axios');
const token = '<REVAI_ACCESS_TOKEN>';

// create a client
const http = axios.create({
  baseURL: 'https://api.rev.ai/topic_extraction/v1/',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
});

// submit a POST request
const submitTopicExtractionJobText = async (textData) => {
  return await http.post(`jobs`,
    JSON.stringify({
      text: textData
    }))
    .then(response => response.data)
    .catch(console.error);
};

Check the status of a topic extraction job

attention

This example uses the Axios HTTP client.

The following example demonstrates how to retrieve the status of a topic extraction job using the Axios HTTP client.

To use this example, set the <REVAI_ACCESS_TOKEN> variable to your Rev AI account's access token.

Copy
Copied
const axios = require('axios');
const token = '<REVAI_ACCESS_TOKEN>';

// create a client
const http = axios.create({
  baseURL: 'https://api.rev.ai/topic_extraction/v1/',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
});

// submit a GET request
const getTopicExtractionJobStatus = async (jobId) => {
  return await http.get(`jobs/${jobId}`)
    .then(response => response.data)
    .catch(console.error);
};

Retrieve a topic extraction report

attention

This example uses the Axios HTTP client.

The following example demonstrates how to retrieve the result of a topic extraction job using the Axios HTTP client.

To use this example, set the <REVAI_ACCESS_TOKEN> variable to your Rev AI account's access token.

Copy
Copied
const axios = require('axios');
const token = '<REVAI_ACCESS_TOKEN>';

// create a client
const http = axios.create({
  baseURL: 'https://api.rev.ai/topic_extraction/v1/',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  }
});

// submit a GET request
const getTopicExtractionJobResult = async (jobId) => {
  return await http.get(`jobs/${jobId}/result`,
    { headers: { 'Accept': 'application/vnd.rev.topic.v1.0+json' } })
    .then(response => response.data)
    .catch(console.error);
};