Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/analytics/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ The Sourcegraph Analytics API is an API that provides programmatic access to you
For Sourcegraph Analytics, you can generate an access token for programmatic access. Tokens are long-lived with an optional expiry and have the same permissions to access instance data as the user who created them.

### Getting Started
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding an info callout block saying that on N date, the cookie used got changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Added note!

> **_NOTE:_** As of July 2025, the authentication cookie has changed from `cas` to `accounts_session_v2` (Sourcegraph Accounts session cookie). If you have existing scripts using the old cookie name, please update them accordingly.

Access tokens are created using the `cas` cookie for authentication to the token creation endpoint. Access tokens are longer lived than the `cas` cookie making them more suitable for programmatic access to the Sourcegraph Analytics API.
Access tokens are created using the Sourcegraph Accounts session cookie (`accounts_session_v2`) for authentication to the token creation endpoint. Access tokens are longer lived than the Sourcegraph Accounts session cookie making them more suitable for programmatic access to the Sourcegraph Analytics API.

- Sign in to [Sourcegraph Analytics](https://analytics.sourcegraph.com).
- Retrieve your session cookie, `cas`, from your browser's developer tools.
- Retrieve your Sourcegraph Accounts session cookie, `accounts_session_v2`, from your browser's developer tools.

![Sourcegraph Analytics session cookie](https://storage.googleapis.com/sourcegraph-assets/Docs/analytics-cookie.png)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I will update this image when https://github.com/sourcegraph/cody-analytics/pull/207 is merged, and we use accounts_session_v2 in production (so it says analyitcs.sourcegraph.com as the cookie source instead of localhost)


- Export the cookie as an environment variable to use in the following commands:

```sh
export CAS_COOKIE="<CAS_COOKIE_VALUE>"
export ACCOUNTS_COOKIE="<ACCOUNTS_SESSION_V2_VALUE>"
```

#### Token creation
Expand All @@ -28,7 +29,7 @@ Create the token by running the following command:
```sh
curl -X POST https://analytics.sourcegraph.com/api/service-access-tokens \
-H "Content-Type: application/json" \
-H "Cookie: cas=$CAS_COOKIE" \
-H "Cookie: accounts_session_v2=$ACCOUNTS_COOKIE" \
-d '{}'

# Optionally include displayName, expiresAt, or both in the request body.
Expand All @@ -54,7 +55,7 @@ List the tokens by running the following command:

```sh
curl -X GET https://analytics.sourcegraph.com/api/service-access-tokens \
-H "Cookie: cas=$CAS_COOKIE"
-H "Cookie: accounts_session_v2=$ACCOUNTS_COOKIE"
```

Each token in the response will include the token ID, creation date, a boolean indicating if the token has expired, and display name and expiration date if provided. For example:
Expand Down Expand Up @@ -98,7 +99,7 @@ Revoke a token by running the following commands:
export TOKEN_ID="<TOKEN_ID>"

curl -X DELETE https://analytics.sourcegraph.com/api/service-access-tokens/$TOKEN_ID \
-H "Cookie: cas=$CAS_COOKIE"
-H "Cookie: accounts_session_v2=$ACCOUNTS_COOKIE"
```

<Callout type="note">The revocation request does not produce output. To verify that a token has been revoked, list the tokens and verify that `isExpired` is `true`.</Callout>
Expand Down