Skip to content

How to Fix Linear API Key Not Working or Returning 401

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Fix Linear API Key Not Working or Returning 401. We cover key concepts, practical examples, and best practices.

Linear API keys authenticate programmatic access to your Linear workspace. When an API request returns 401 Unauthorized or 403 Forbidden, the key is invalid, revoked, or lacks the required permissions for the requested resource.

The Problem

Your API call to https://api.linear.app/<a href="/apis/graphql/">graphql</a>:

query { viewer { id name } }

Returns:

{
  "errors": [{"message": "401: Unauthorized"}]
}

Wrong approach — hardcoding a new key directly in the source code.

The Fix

Verify the key is active:

1. Linear → Settings → API → Personal API keys
2. Find your key in the list
3. If it shows "Revoked" or is not listed, create a new key
4. Copy the new key immediately (keys are only shown once)

Check the key has the required scope:

1. When creating a key, scopes are shown: Admin, Read, Write, Issues, etc.
2. If your key was created with "Read" scope but you are trying to mutate data, it will fail
3. Create a new key with the appropriate scopes for your use case
4. Delete old keys with insufficient scopes

For organization-level API access, use a separate admin key:

1. Admin keys have access to all teams
2. User keys only access teams the user is a member of
3. For workspace-wide automation, use an admin account's API key

Expected output:

API returns 200 with the requested data
GraphQL mutations succeed with proper authorization
Responses include the expected fields without errors

Prevention Tips

  • Create separate API keys for each application or integration
  • Use the minimum required scope for each key
  • Rotate keys every 90 days
  • Store keys in environment variables or a secrets manager
  • Monitor key usage in Linear's API logs
  • Revoke keys immediately when an application is decommissioned

Common Mistakes with api key

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world LINEAR code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What scopes are available for Linear API keys?

Key scopes include: Admin (full access), Read (read-only), Write (create and update issues), Issues (issue-specific access), and more. Choose the narrowest scope that still allows your integration to function.

Why does my key work in the Linear API playground but not in my code?

The playground uses your current browser session for authentication, not the API key. Your code must pass the API key in the Authorization header: Authorization: YOUR_API_KEY. Check that the header is correctly formatted.

Can I use OAuth instead of API keys in Linear?

Yes, Linear supports OAuth 2.0 for integrations that need user-level authorization. OAuth is recommended for applications that multiple users will authorize through their own accounts. API keys are simpler for server-to-server integrations.

Related: DodaTech's API Key Manager securely generates, stores, and rotates Linear API keys, with usage monitoring and automatic revocation for inactive keys. Use with DodaZIP for encrypted key storage.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro