# Get Automation Click Tracking Stats by ID

## API Overview

As a Marketing Campaigns customer, you have access to rich statistics about your Single Sends and Automations. The Marketing Campaigns Statistics API allows you to retrieve these statistics programmatically. for detailed information about the statistics available, see the [**Marketing Campaigns Stats Overview**](/docs/sendgrid/ui/analytics-and-reporting/marketing-campaigns-stats-overview).

> \[!NOTE]
>
> These endpoints provide stats for Marketing Campaigns only. For stats related to event tracking, please see the [**Stats API**](/docs/sendgrid/api-reference/stats).

## Operation overview

```json
{"path":"https://api.sendgrid.com/v3/marketing/stats/automations/{id}/links","method":"get","servers":[{"url":"https://api.sendgrid.com","description":"The Twilio SendGrid v3 API"}]}
```

**This endpoint lets you retrieve click-tracking stats for a single Automation**.

The stats returned list the URLs embedded in your Automation and the number of clicks each one received.

## Operation details

### Authentication

API Key

### Headers

```json
[{"in":"header","name":"Authorization","required":true,"default":"Bearer <<YOUR_API_KEY_HERE>>","schema":{"type":"string"}}]
```

### Path parameters

```json
[{"name":"id","in":"path","description":"The ID of the Automation you want to get click tracking stats for. ","required":true,"schema":{"type":"string","format":"uuid"}}]
```

### Query string

```json
[{"name":"group_by","in":"query","description":"Automations can have multiple steps. Including `step_id` as a `group_by` metric allows further granularity of stats.","style":"form","explode":false,"schema":{"type":"array","items":{"type":"string","enum":["step_id"],"refName":"Items","modelName":"Items"}},"refName":"#/components/parameters/AutomationQueryParamsGroupBy","modelName":"__components_parameters_AutomationQueryParamsGroupBy"},{"name":"step_ids","in":"query","description":"Comma-separated list of `step_ids` that you want the link stats for.","style":"form","explode":false,"schema":{"type":"array","items":{"type":"string","format":"uuid"},"uniqueItems":true},"refName":"#/components/parameters/AutomationQueryParamsStepId","modelName":"__components_parameters_AutomationQueryParamsStepId"},{"name":"page_size","in":"query","description":"The number of elements you want returned on each page.","schema":{"type":"integer","minimum":1,"maximum":50,"default":25},"refName":"#/components/parameters/PaginationPageSize","modelName":"__components_parameters_PaginationPageSize"},{"name":"page_token","in":"query","description":"The stats endpoints are paginated. To get the next page, call the passed `_metadata.next` URL. If `_metadata.prev` doesn't exist, you're at the first page. Similarly, if `_metadata.next` is not present, you're at the last page.","schema":{"type":"string"},"refName":"#/components/parameters/PaginationPageToken","modelName":"__components_parameters_PaginationPageToken"}]
```

### Responses

```json
[{"responseCode":"200","schema":{"description":"","content":{"application/json":{"schema":{"title":"AutmoationsLinkStatsResponse","type":"object","required":["results","total_clicks","_metadata"],"refName":"AutmoationsLinkStatsResponse","modelName":"AutmoationsLinkStatsResponse","properties":{"results":{"type":"array","description":"","items":{"type":"object","required":["url","step_id","clicks"],"properties":{"url":{"type":"string","description":"This is the URL of the link clicked. If `{{custom_fields}}` are part of the URL, they will be included.","format":"uri"},"url_location":{"type":"integer","description":"This is the location of the link clicked in each Automation step. Links are located according to their position within the message; the topmost link has index `0`.","minimum":0},"step_id":{"type":"string","description":"This is the ID of the step if the stats were requested to be grouped by `step_id`.","format":"uuid"},"clicks":{"type":"integer","minimum":1,"description":"The number of clicks on this particular link."}}}},"total_clicks":{"type":"integer"},"_metadata":{"title":"link tracking metadata","type":"object","refName":"LinkTrackingMetadata","modelName":"LinkTrackingMetadata","properties":{"prev":{"type":"string","format":"uri","description":"The URL of the previous page of results. If this field isn't present, you're at the start of the list."},"self":{"type":"string","format":"uri","description":"The URL of the current page of results."},"next":{"type":"string","format":"uri","description":"The URL of the next page of results. If this field isn't present, you're at the end of the list."},"count":{"type":"number","description":"The number of items in the entire list, i.e., across all pages."}}}}}}}}},{"responseCode":"400","schema":{"description":"","content":{"application/json":{"schema":{"type":"object","example":{"errors":[{"field":"field_name","message":"error message"}]},"refName":"ErrorResponse","modelName":"ErrorResponse","properties":{"errors":{"type":"array","items":{"type":"object","properties":{"message":{"type":"string","description":"An error message."},"field":{"description":"When applicable, this property value will be the field that generated the error.","nullable":true,"type":"string"},"help":{"type":"object","description":"When applicable, this property value will be helper text or a link to documentation to help you troubleshoot the error."}}}},"id":{"type":"string","description":"When applicable, this property value will be an error ID."}}}}},"refName":"#/components/responses/Stats400","modelName":"__components_responses_Stats400"}},{"responseCode":"404","schema":{"description":"","content":{"application/json":{"schema":{"type":"object","example":{"errors":[{"field":"field_name","message":"error message"}]},"refName":"ErrorResponse","modelName":"ErrorResponse","properties":{"errors":{"type":"array","items":{"type":"object","properties":{"message":{"type":"string","description":"An error message."},"field":{"description":"When applicable, this property value will be the field that generated the error.","nullable":true,"type":"string"},"help":{"type":"object","description":"When applicable, this property value will be helper text or a link to documentation to help you troubleshoot the error."}}}},"id":{"type":"string","description":"When applicable, this property value will be an error ID."}}}}}}}]
```

Get Automation Click Tracking Stats by ID

```js
const client = require("@sendgrid/client");
client.setApiKey(process.env.SENDGRID_API_KEY);

const id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";

const request = {
  url: `/v3/marketing/stats/automations/${id}/links`,
  method: "GET",
};

client
  .request(request)
  .then(([response, body]) => {
    console.log(response.statusCode);
    console.log(response.body);
  })
  .catch((error) => {
    console.error(error);
  });
```

```python
import os
from sendgrid import SendGridAPIClient


sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))

id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644"

response = sg.client.marketing.stats.automations._(id).links.get()

print(response.status_code)
print(response.body)
print(response.headers)
```

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SendGrid;

public class Program {
    public static async Task Main() {
        string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);

        var id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.GET, urlPath: $"marketing/stats/automations/{id}/links");

        Console.WriteLine(response.StatusCode);
        Console.WriteLine(response.Body.ReadAsStringAsync().Result);
        Console.WriteLine(response.Headers.ToString());
    }
}
```

```java
import com.sendgrid.*;
import java.io.IOException;

public class Example {
    public static void main(String[] args) throws IOException {
        try {
            SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
            Request request = new Request();
            request.setMethod(Method.GET);
            request.setEndpoint("/marketing/stats/automations/f15982c1-a82c-4e87-a6b2-a4a63b4b7644/links");
            Response response = sg.api(request);
            System.out.println(response.getStatusCode());
            System.out.println(response.getBody());
            System.out.println(response.getHeaders());
        } catch (IOException ex) {
            throw ex;
        }
    }
}
```

```go
package main

import (
	"fmt"
	"github.com/sendgrid/sendgrid-go"
	"os"
)

func main() {
	apiKey := os.Getenv("SENDGRID_API_KEY")
	host := "https://api.sendgrid.com"
	request := sendgrid.GetRequest(apiKey, "/v3/marketing/stats/automations/f15982c1-a82c-4e87-a6b2-a4a63b4b7644/links", host)
	request.Method = "GET"
	response, err := sendgrid.API(request)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		fmt.Println(response.StatusCode)
		fmt.Println(response.Body)
		fmt.Println(response.Headers)
	}
}
```

```php
<?php
// Uncomment the next line if you're using a dependency loader (such as Composer) (recommended)
// require 'vendor/autoload.php';

// Uncomment next line if you're not using a dependency loader (such as Composer)
// require_once '<PATH TO>/sendgrid-php.php';

$apiKey = getenv("SENDGRID_API_KEY");
$sg = new \SendGrid($apiKey);
$id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644";

try {
    $response = $sg->client
        ->marketing()
        ->stats()
        ->automations()
        ->_($id)
        ->links()
        ->get();
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $ex) {
    echo "Caught exception: " . $ex->getMessage();
}
```

```ruby
require 'sendgrid-ruby'
include SendGrid

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
id = "f15982c1-a82c-4e87-a6b2-a4a63b4b7644"

response = sg.client.marketing.stats.automations._(id).links.get()
puts response.status_code
puts response.headers
puts response.body
```

```bash
curl -X GET "https://api.sendgrid.com/v3/marketing/stats/automations/f15982c1-a82c-4e87-a6b2-a4a63b4b7644/links" \
--header "Authorization: Bearer $SENDGRID_API_KEY"
```
