AlexxIT/go2rtc · error

ring: invalid camera_id

Error message

ring: invalid camera_id: %w

What it means

Dial() builds a ring camera Client and converts the cameraID string to an int with strconv.Atoi. When the provided camera_id is not a valid integer (or empty), Atoi fails and Dial wraps the parse error with this message. The library refuses to construct a Client with an unusable camera identifier rather than failing later at request time.

Solutions

  1. Print the input cameraID and confirm it is purely digits (strconv.Atoi-compatible).
  2. Look up the correct numeric camera ID for the device and pass that instead of a name/UUID.
  3. Trim whitespace/newlines from the value before passing it in.
  4. Fix the config file or environment variable that supplies the camera_id so it is never empty.

Example fix

// before
c, err := ring.Dial(ctx, "front-door-cam", token)
// after
c, err := ring.Dial(ctx, "12345678", token)
Defensive patterns

Strategy: validation

Validate before calling

if cameraID == "" {
    return errors.New("camera_id must not be empty")
}
if _, err := strconv.Atoi(strings.TrimSpace(cameraID)); err != nil {
    return fmt.Errorf("camera_id must be numeric, got %q", cameraID)
}

Try / catch

client, err := ring.Dial(ctx, cameraID, token)
if err != nil {
    if strings.Contains(err.Error(), "invalid camera_id") {
        // surface a config fix prompt to the user
    }
    return err
}

Prevention

When it happens

Trigger: Calling ring.Dial with a camera_id that is empty, contains letters/symbols/whitespace, has a URL prefix, or is a non-numeric identifier (e.g. a device UUID instead of the numeric camera ID).

Common situations: Passing a Ring device name or UUID copied from the web UI instead of the numeric camera ID; an empty/unset config value; trimming issues leaving a trailing newline or space in the ID from an env var or config file.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/431006f78cecb482. Report an issue: GitHub.

Appendix: source

Thrown at pkg/ring/client.go:48

	}

	query := u.Query()
	encodedToken := query.Get("refresh_token")
	cameraID := query.Get("camera_id")
	deviceID := query.Get("device_id")
	_, isSnapshot := query["snapshot"]

	if encodedToken == "" || deviceID == "" || cameraID == "" {
		return nil, errors.New("ring: wrong query")
	}

	client := &Client{
		dialogID: uuid.NewString(),
	}

	client.cameraID, err = strconv.Atoi(cameraID)
	if err != nil {
		return nil, fmt.Errorf("ring: invalid camera_id: %w", err)
	}

	refreshToken, err := url.QueryUnescape(encodedToken)
	if err != nil {
		return nil, fmt.Errorf("ring: invalid refresh token encoding: %w", err)
	}

	client.api, err = NewRestClient(RefreshTokenAuth{RefreshToken: refreshToken}, nil)
	if err != nil {
		return nil, err
	}

	// Snapshot Flow
	if isSnapshot {
		client.prod = NewSnapshotProducer(client.api, client.cameraID)
		return client, nil
	}

View on GitHub (pinned to c245815e75)