play-console-cli icon indicating copy to clipboard operation
play-console-cli copied to clipboard

Feature: Play Custom App Publishing API integration (playcustomapp/v1)

Open tamtom opened this issue 8 months ago • 3 comments

Summary

Add support for the Google Play Custom App Publishing API (playcustomapp/v1), enabling creation and publishing of permanently private Android apps to managed Google Play for enterprise customers directly from the CLI.

Why this is applicable to Google Play

The Play Custom App Publishing API serves a distinct enterprise use case: managed Google Play for organizations using EMM (Enterprise Mobility Management). Custom apps are permanently private apps that can only be distributed within a specific organization's managed Google Play store. Unlike the standard Android Publisher API workflow, custom apps go through a streamlined verification process and appear in the managed Play Store within ~5 minutes of publishing. This API is used by EMMs, IT admins, and enterprise developers who need to deploy internal-only apps without touching the Play Console UI.

Problem

The gplay CLI currently covers the standard Android Publisher API (androidpublisher/v3) comprehensively — tracks, releases, bundles, APKs, listings, etc. However, there is no support for the Custom App Publishing API, which is a separate Google API (playcustomapp/v1) with its own endpoint (playcustomapp.googleapis.com). Enterprise users who manage custom/private apps for their organizations must fall back to the Play Console UI or write custom scripts. Adding this closes the gap for enterprise/managed Google Play workflows.

Goals

  • Provide a gplay custom-apps command group for managing custom enterprise apps
  • Support creating (publishing) a new custom app with APK upload in a single command
  • Support scoping custom apps to specific organizations
  • Follow existing CLI patterns (JSON-first output, --dry-run, upload timeouts, flag validation)
  • Introduce a dedicated client wrapper for the playcustomapp/v1 API alongside the existing playclient

Proposed Commands

gplay custom-apps create

Create and publish a new permanently private custom app to managed Google Play.

gplay custom-apps create \
  --account <developer-account-id> \
  --title "My Internal App" \
  --language en-US \
  --apk /path/to/app.apk \
  --organization-id <org-id> \
  --organization-name "Acme Corp" \
  --output json

Flags:

Flag Required Description
--account Yes Developer account ID (numeric, from Play Console URL)
--title Yes App title (must be unique within the developer account)
--language No Default listing language in BCP 47 format (default: en-US)
--apk Yes Path to APK file to upload (max 100 MB)
--organization-id No Organization ID to grant access (repeatable for multiple orgs)
--organization-name No Human-readable org name (paired with --organization-id)
--output No Output format: json (default), table, markdown
--pretty No Pretty-print JSON output

Output (JSON):

{
  "packageName": "com.example.internal.app",
  "title": "My Internal App",
  "languageCode": "en-US",
  "organizations": [
    {
      "organizationId": "C0123wxyz",
      "organizationName": "Acme Corp"
    }
  ]
}

gplay custom-apps (group)

Parent command that lists subcommands.

gplay custom-apps --help

Note on updates: Updating an existing custom app (uploading a new APK version) uses the standard Android Publisher API edits workflow, which is already supported via gplay release, gplay edits, gplay bundles upload, and gplay apks upload. The playcustomapp/v1 API only handles initial creation. The --help text for custom-apps should mention this and cross-reference the existing commands.

Implementation Details

API Endpoints

  • Upload URI (multipart): POST https://playcustomapp.googleapis.com/upload/playcustomapp/v1/accounts/{account}/customApps
  • Metadata URI: POST https://playcustomapp.googleapis.com/playcustomapp/v1/accounts/{account}/customApps
  • Upload protocol: Multipart (uploadType=multipart) — APK binary + JSON metadata in a single request
  • Max upload size: 100 MB
  • Accepted MIME types: application/octet-stream, application/vnd.android.package-archive

Authentication Requirements

  • OAuth2 scope: https://www.googleapis.com/auth/androidpublisher (same scope already used by playclient)
  • The service account must have "Create and publish private apps" permission granted in Play Console
  • The existing credential resolution in playclient can be reused since the scope is identical

New Packages/Files

internal/
├── cli/
│   └── customapps/
│       ├── customapps.go          # Command group definition
│       ├── customapps_test.go     # Command group tests
│       ├── create.go              # Create subcommand
│       └── create_test.go         # Create subcommand tests
├── customappclient/
│   ├── client.go                  # playcustomapp/v1 service wrapper
│   └── client_test.go             # Client tests

Client Implementation Notes

Create internal/customappclient/client.go as a thin wrapper around the Go client library:

import "google.golang.org/api/playcustomapp/v1"
  • The playcustomapp/v1 package is part of google.golang.org/api (already at v0.272.0 in go.mod), so no new top-level dependency is needed — just import the sub-package
  • Mirror the playclient.Service pattern: struct wrapping the API service + config, with a NewService(ctx) constructor
  • Reuse playclient's credential resolution logic (extract the HTTP client creation into a shared helper, or call into playclient for the authenticated *http.Client)
  • Support --dry-run by wrapping the transport with shared.DryRunTransport, same as playclient

Upload Handling

  • Use shared.ContextWithUploadTimeout for the upload context (respects GPLAY_UPLOAD_TIMEOUT)
  • The Go client's AccountsCustomAppsCreateCall.Media(r io.Reader) handles multipart upload automatically
  • Validate APK file exists and is readable before initiating the API call
  • Validate file size does not exceed 100 MB
  • Validate file extension is .apk (the API does not support AAB for custom apps)

Output Format

  • JSON (minified) by default — serialize the returned CustomApp object
  • Table format: single row with columns Package Name, Title, Language, Organizations
  • Markdown format: same columns as table
  • Use existing shared.PrintResult / output formatting helpers

Registry Registration

Add to internal/cli/registry/registry.go:

import "github.com/tamtom/play-console-cli/internal/cli/customapps"

// In Subcommands():
customapps.CustomAppsCommand(),

Acceptance Criteria

  • [ ] gplay custom-apps --help displays the command group with available subcommands
  • [ ] gplay custom-apps create --help displays all flags with descriptions
  • [ ] gplay custom-apps create validates required flags (--account, --title, --apk) and prints actionable errors to stderr
  • [ ] gplay custom-apps create uploads an APK and creates a custom app via the playcustomapp/v1 API
  • [ ] gplay custom-apps create --organization-id correctly scopes the app to the specified organization(s)
  • [ ] gplay custom-apps create --dry-run logs the request to stderr without executing
  • [ ] gplay custom-apps create --output table and --output markdown produce formatted output
  • [ ] gplay custom-apps create --pretty pretty-prints JSON output
  • [ ] APK file validation: rejects missing files, non-.apk extensions, and files exceeding 100 MB
  • [ ] Upload uses shared.ContextWithUploadTimeout to respect GPLAY_UPLOAD_TIMEOUT
  • [ ] customappclient.NewService reuses existing credential resolution (service account / OAuth)
  • [ ] Unit tests cover flag validation, error paths, and output formatting
  • [ ] Integration test structure exists (can be skipped in CI without credentials)
  • [ ] Command registered in registry.go
  • [ ] gplay docs generate includes the new command group

References

tamtom avatar Apr 04 '26 18:04 tamtom

Implementation Checklist

Command & Registration

  • [ ] Command group gplay custom-apps in internal/cli/customapps/
  • [ ] Registered in internal/cli/registry/registry.go
  • [ ] UsageFunc: shared.DefaultUsageFunc set on command and subcommands
  • [ ] Dedicated client wrapper for playcustomapp/v1 API (separate from playclient)
  • [ ] Required flags validated with stderr error messages
  • [ ] shared.ContextWithUploadTimeout used for APK upload calls

Tests

  • [ ] CLI black-box tests in internal/cmdtest/custom_apps_test.go
  • [ ] Package-level unit tests for flag validation and org-id pairing logic
  • [ ] Error paths: missing --account, missing --title, missing --apk, invalid APK path, conflicting flags

Docs & Help

  • [ ] --help output follows existing conventions
  • [ ] Command docs regenerated: gplay docs generate

Validation (before opening PR)

make format
make lint
make test
make build
/tmp/gplay custom-apps --help
/tmp/gplay custom-apps create --help
/tmp/gplay custom-apps create            # missing required flags → stderr error
/tmp/gplay custom-apps create --account 123 --title "Test" --apk /bad/path  # invalid APK

tamtom avatar Apr 05 '26 04:04 tamtom

Addendum to checklist above — docs CI gate:

The PR CI now runs make check-docs on every PR. This means:

  1. After implementing the command, run make docs to regenerate GPLAY.md
  2. Commit the updated GPLAY.md alongside your code changes
  3. If you forget, the PR check will fail with: "GPLAY.md is out of date"

This ensures every user-facing command, flag, and help text is always reflected in the reference docs.

tamtom avatar Apr 05 '26 04:04 tamtom

Shipped in #244 (v0.7.0). Try it: gplay custom-apps create --help. Tracking future related work in the roadmap: #245.

tamtom avatar Jul 05 '26 10:07 tamtom