From 9b62c9cc075343fdfa9865652d49316f0cab9dfa Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Thu, 31 Jul 2025 10:59:54 -0700 Subject: [PATCH] analytics: replace access token creation with management UI --- docs/analytics/api.mdx | 97 +----------------------------------------- 1 file changed, 1 insertion(+), 96 deletions(-) diff --git a/docs/analytics/api.mdx b/docs/analytics/api.mdx index 54aa3d08b..b15813b8d 100644 --- a/docs/analytics/api.mdx +++ b/docs/analytics/api.mdx @@ -6,102 +6,7 @@ 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 - -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. - -- Sign in to [Sourcegraph Analytics](https://analytics.sourcegraph.com). -- Retrieve your session cookie, `cas`, from your browser's developer tools. - -![Sourcegraph Analytics session cookie](https://storage.googleapis.com/sourcegraph-assets/Docs/analytics-cookie.png) - -- Export the cookie as an environment variable to use in the following commands: - -```sh -export CAS_COOKIE="" -``` - -#### Token creation - -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" \ - -d '{}' - -# Optionally include displayName, expiresAt, or both in the request body. -# If expiresAt is not provided, the token will never expire and must be revoked manually. -# -d '{"displayName": "My Analytics Token", "expiresAt": "2025-12-31T23:59:59Z"}' -``` - -The response will include the token ID, secret, creation date, and, if provided, display name and expiration date. For example: - -```json -{ - "id": "4cf96e80-d5f3-4af0-a28d-3c70ba97abb4", - "displayName": "My Analytics Token", - "secret": "sams_at_abcdefghijk", - "createdAt": "2025-05-28T12:00:00Z", - "expiresAt": "2025-12-31T23:59:59Z" -} -``` - -#### Token listing - -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" -``` - -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: - -```json -{ - "tokens": [ - { - "id": "5a140b00-3a79-497d-bcfb-c1d2e3d8c747", - "displayName": "My Analytics Token", - "createdAt": "2025-05-27T12:00:00Z", - "expiresAt": "2025-05-27T13:00:00Z", - "isExpired": true - }, - { - "id": "eaf8a6f1-1302-43f6-a9ad-f9862d75e959", - "createdAt": "2025-05-28T12:30:00Z", - "expiresAt": "2025-05-28T13:30:00Z", - "isExpired": true - }, - { - "id": "d7df6636-99d0-4266-9f32-a2fb7ccbfcd5", - "displayName": "My Analytics Token 2", - "createdAt": "2025-05-28T15:00:00Z", - "isExpired": false - }, - { - "id": "8ea63000-a164-44ca-8834-bb71e9b788fb", - "createdAt": "2025-05-28T15:30:00Z", - "isExpired": false - } - ] -} -``` - -#### Token revocation - -Revoke a token by running the following commands: - -```sh -export TOKEN_ID="" - -curl -X DELETE https://analytics.sourcegraph.com/api/service-access-tokens/$TOKEN_ID \ - -H "Cookie: cas=$CAS_COOKIE" -``` - -The revocation request does not produce output. To verify that a token has been revoked, list the tokens and verify that `isExpired` is `true`. +To get started, visit the [Sourcegraph Analytics access tokens management page](http://analytics.sourcegraph.com/access-tokens). From here, you can create, view, and revoke access tokens for your Sourcegraph Account. ## API reference