# Get Started

This short tutorial will teach you the basics of using the Sentiment Analysis API. It demonstrates how to analyze the sentiments of a transcript.

## Assumptions

This tutorial assumes that

- You have a Rev AI account. If not, [sign up for a free account](https://www.rev.ai/auth/signup).
- You have a JSON transcript generated from the [Asynchronous Speech-to-Text API](/api/asynchronous). If not, use this [example JSON transcript](https://www.rev.ai/FTC_Sample_1_Transcript.json).


If you have an audio file, you can [generate a JSON transcript](/api/asynchronous/get-started) from it.

## Step 1: Get your access token

The first step is to generate an access token, which will enable access to the Rev AI APIs. Follow these steps:

1. [Log in](https://www.rev.ai/auth/login) to Rev AI.
2. Navigate to the [**Access Token** page](https://www.rev.ai/access-token).
3. Click the **Generate New Access Token** link. Confirm the operation in the pop-up dialog box.


![Creating an access token](/images/create-token.png)

The new access token will be generated and displayed on the screen.

Save your access tokens somewhere safe; you will only be able to see them once. You are allowed a maximum of 2 access tokens at a time.

## Step 2: Submit the transcript for sentiment analysis

Assuming that your JSON transcript is in a file, submit the transcript to the Sentiment Analysis API using the command below. Replace the `<REVAI_ACCESS_TOKEN>` placeholder with the access token obtained in [Step 1](#step-1-get-your-access-token) and the `<FILEPATH>` placeholder with the path to the transcript file.


```bash
curl -X POST "https://api.rev.ai/sentiment_analysis/v1/jobs" \
     -H "Authorization: Bearer <REVAI_ACCESS_TOKEN>" \
     -H "Content-Type: application/json"  \
     -d '{"json":'"$(< <FILEPATH>)"',"metadata":"This is a test"}'
```

You'll receive a response like this:


```bash
{
  "id":"XaFhKguSg912",
  "created_on":"2022-02-02T14:16:25.892Z",
  "metadata":"This is a test",
  "status":"in_progress",
  "type":"sentiment_analysis"
}
```

The `id` (in this case `XaFhKguSg912`) will allow you to retrieve the sentiment analysis report.

## Step 3: Retrieve the sentiment analysis report

You now need to wait for the job to complete. Wait for approximately 30 seconds and then check the `status` of your job by querying the API as shown below:


```bash
curl -X GET https://api.rev.ai/sentiment_analysis/v1/jobs/<ID> \
     -H "Authorization: Bearer <REVAI_ACCESS_TOKEN>"
```

Polling the API periodically for job status is NOT recommended in a production server. Rather, use [webhooks](/api/sentiment-analysis/webhooks) to asynchronously receive notifications once the sentiment analysis job completes.

Once the sentiment analysis job's `status` changes to `completed`, you can retrieve the results in JSON format by running the command below. As before, replace the `<REVAI_ACCESS_TOKEN>` placeholder with the access token obtained in [Step 1](#step-1-get-your-access-token). You must also replace the `<ID>` placeholder with the `id` obtained in [Step 2](#step-2-submit-the-transcript-for-sentiment-analysis).


```bash
curl -X GET "https://api.rev.ai/sentiment_analysis/v1/jobs/<ID>/result" \
     -H "Authorization: Bearer <REVAI_ACCESS_TOKEN>" \
     -H "Accept: application/vnd.rev.sentiment.v1.0+json"
```

Here is an example of the output:


```javascript
{
  "messages": [
    {
      "content": "Hi, my name's Jack Ratzinger.",
      "score": 0,
      "sentiment": "neutral",
      "ts": 0.27,
      "end_ts": 1.5
    },
    {
      "content": "And I'm going to be talking about how to recruit a co-founder and a team for your startup.",
      "score": 0,
      "sentiment": "neutral",
      "ts": 1.53,
      "end_ts": 5.85
    },
    {
      "content": "First, give a quick overview of what we're going to talk about.",
      "score": -0.601,
      "sentiment": "negative",
      "ts": 6.72,
      "end_ts": 8.79
    },
    {
      "content": "We're going to start out by talking about the sorts of folks you might be looking for for your startup.",
      "score": 0.2,
      "sentiment": "neutral",
      "ts": 9.09,
      "end_ts": 13.14
    },
    {
      ...
    }
  ]
}
```

## Next steps

You should now have a basic idea of how to use the Sentiment Analysis API. To learn more, read [the API documentation](/api/sentiment-analysis) for complete details on the different resources and operations available in this API. You can also read about our [other APIs](/api) and find [code samples and SDK documentation](/sdk) that will help you connect your application with the API.