larksuite/cli · error

fetch bot info: bot identity is not available in current cre

Error message

fetch bot info: bot identity is not available in current credential context

What it means

fetchBotInfo refuses to call /bot/v3/info when the current credential context cannot act as a bot (ctx.Config.CanBot() is false). The configured credentials are user/tenant tokens without a bot app identity, so bot info is unobtainable. This is a configuration/credential-shape problem, not a network failure.

Source

Thrown at shortcuts/common/runner.go:161

}

// BotInfo returns the bot's open_id and display name, fetched lazily from /bot/v3/info.
// Unlike UserOpenId() (which reads from config), this requires a network call and may fail.
// Thread-safe via sync.OnceValues; the API is called at most once per RuntimeContext.
func (ctx *RuntimeContext) BotInfo() (*BotInfo, error) {
	if ctx.offline {
		return nil, errs.NewValidationError(errs.SubtypeFailedPrecondition, "BotInfo is unavailable during dry-run")
	}
	if ctx.botInfoFunc == nil {
		return nil, fmt.Errorf("BotInfo not available (runtime context not fully initialized)")
	}
	return ctx.botInfoFunc()
}

// fetchBotInfo calls /bot/v3/info using bot identity and parses the response.
func (ctx *RuntimeContext) fetchBotInfo() (*BotInfo, error) {
	if !ctx.Config.CanBot() {
		return nil, fmt.Errorf("fetch bot info: bot identity is not available in current credential context")
	}
	resp, err := ctx.DoAPIAsBot(&larkcore.ApiReq{
		HttpMethod: http.MethodGet,
		ApiPath:    "/open-apis/bot/v3/info",
	})
	if err != nil {
		return nil, fmt.Errorf("fetch bot info: %w", err)
	}
	if resp.StatusCode >= 400 {
		return nil, fmt.Errorf("fetch bot info: HTTP %d", resp.StatusCode)
	}
	// /open-apis/bot/v3/info returns `{code, msg, bot: {...}}` — the bot
	// payload is under "bot", not "data" as the newer Lark API convention.
	var envelope struct {
		Code int    `json:"code"`
		Msg  string `json:"msg"`
		Data struct {
			OpenID  string `json:"open_id"`

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Configure bot-capable credentials (app credentials for an app with the Lark bot capability enabled) in the active profile
  2. Switch to a profile/credential context that CanBot() before running the command
  3. Avoid the bot path: provide the identity explicitly (e.g. pass the ID or use a different identity source flag) instead of deriving it from bot info

Example fix

// before
id, err := ctx.selfAttendeeId() // fails with non-bot creds
// after
if !ctx.Config.CanBot() { return errs.NewValidationError(errs.SubtypeFailedPrecondition, "this command requires bot credentials; configure a bot-enabled app") }
Defensive patterns

Strategy: validation

Validate before calling

if !ctx.Config.CanBot() {
	return errs.NewValidationError(errs.SubtypeFailedPrecondition, "requires bot credentials")
}
info, err := ctx.BotInfo()

Type guard

func canUseBotIdentity(ctx *common.RuntimeContext) bool { return ctx.Config.CanBot() }

Try / catch

info, err := ctx.BotInfo()
var ve *errs.ValidationError
if errors.As(err, &ve) || strings.Contains(err.Error(), "bot identity is not available") {
	// fall back to explicit identity flag or ask user to configure bot creds
}

Prevention

When it happens

Trigger: BotInfo() called while the active config lacks bot credentials — e.g. user access token auth only, an app without bot capability enabled, or credentials for an app type that cannot call bot APIs.

Common situations: Running a shortcut that resolves the attendee/identity from bot info while the CLI is authenticated with a non-bot app; enabling a bot-dependent feature under credentials configured for plain API access.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/bad7a476eb66d1c8. Report an issue: GitHub.