Skip to content

Instantly share code, notes, and snippets.

@erikologic
Last active June 19, 2026 16:09
Show Gist options
  • Select an option

  • Save erikologic/e08ffc748584bdc639b9f4a998b4a012 to your computer and use it in GitHub Desktop.

Select an option

Save erikologic/e08ffc748584bdc639b9f4a998b4a012 to your computer and use it in GitHub Desktop.
Restish + Gmail CLI - OAuth pagination tools (no secrets exposed)

Restish + Gmail Configuration

Setup

Google Cloud OAuth app with redirect URI http://localhost:8080.

Restish Config (~/.config/restish/restish.json)

{
  "apis": {
    "gmail": {
      "base_url": "https://www.googleapis.com",
      "spec_url": "https://raw.githubusercontent.com/APIs-guru/openapi-directory/main/APIs/googleapis.com/gmail/v1/openapi.yaml",
      "pagination": {
        "next_path": "nextPageToken",
        "page_param": "pageToken"
      },
      "profiles": {
        "default": {
          "auth": {
            "type": "oauth-authorization-code",
            "params": {
              "authorize_url": "https://accounts.google.com/o/oauth2/auth",
              "token_url": "https://oauth2.googleapis.com/token",
              "client_id": "env:GMAIL_CLIENT_ID",
              "client_secret": "env:GMAIL_CLIENT_SECRET",
              "scopes": "https://mail.google.com/ https://www.googleapis.com/auth/gmail.modify",
              "redirect_port": "8080"
            }
          }
        }
      }
    }
  }
}

Environment Variables

export GMAIL_CLIENT_ID="<your_client_id_from_google_cloud>"
export GMAIL_CLIENT_SECRET="<your_client_secret_from_google_cloud>"

Key Settings

  • redirect_port: "8080" - Must match Google app config
  • gmail.modify scope - Enables label operations
  • nextPageToken pagination - Gmail's cursor style

First Run

restish gmail gmail-users-labels-list me

Opens browser for OAuth, caches token for future runs.

Operations

All 79 Gmail API operations available:

restish gmail --help
#!/bin/bash
# Usage: paginate <next-token-jq> <items-jq> <command> [args...]
# Example: paginate '.nextPageToken' '.messages[]' restish gmail gmail-users-messages-list me
paginate() {
local next_token_path=$1
local items_path=$2
shift 2
local page_token=""
while true; do
local args=("$@")
if [ -n "$page_token" ]; then
args+=(--page-token "$page_token")
fi
local response=$("${args[@]}" 2>/dev/null)
echo "$response" | jq -c "$items_path"
page_token=$(echo "$response" | jq -r "$next_token_path // empty")
[ -z "$page_token" ] && break
done
}
paginate "$@"
# Restish + Gmail CLI
Complete setup for using restish CLI with Gmail API.
## Files
- `restish` - Overview
- `paginate` - Pagination handler
- `CONFIGURATION.md` - OAuth setup
## Quick Start
```bash
restish gmail gmail-users-labels-list me
```
## Usage
### Paginate
```bash
paginate '.nextPageToken' '.messages[]' restish gmail gmail-users-messages-list me
paginate '.nextPageToken' '.labels[]' restish gmail gmail-users-labels-list me
```
### Label operations
```bash
restish gmail gmail-users-messages-modify me MSG_ID -d '{"addLabelIds": ["LABEL_ID"]}'
restish gmail gmail-users-messages-modify me MSG_ID -d '{"removeLabelIds": ["LABEL_ID"]}'
```
All 79 operations: `restish gmail --help`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment