w7corp/easywechat · error · HttpException
Failed to get jssdk agentTicket: %s
Error message
Failed to get jssdk agentTicket: %s
What it means
getAgentTicket() returns the agent_config JS-SDK ticket used for third-party app agents (wx.agentConfig). It is cached per agentId (key '<base-key>.<agentId>'); on miss it GETs /cgi-bin/ticket/get?type=agent_config and throws HttpException with the raw JSON when no ticket comes back. Failures trace to the credential chain or the state of that specific agent.
Source
Thrown at src/OpenWork/JsApiTicket.php:118
];
}
/**
* @throws HttpException
*/
public function getAgentTicket(int $agentId): string
{
$key = $this->getAgentKey($agentId);
$ticket = $this->cache->get($key);
if ($ticket && is_string($ticket)) {
return $ticket;
}
$response = $this->httpClient->request('GET', '/cgi-bin/ticket/get', ['query' => ['type' => 'agent_config']])->toArray(false);
if (empty($response['ticket'])) {
throw new HttpException('Failed to get jssdk agentTicket: '.json_encode($response, JSON_UNESCAPED_UNICODE));
}
$this->cache->set($key, $response['ticket'], intval($response['expires_in']));
return $response['ticket'];
}
public function getAgentKey(int $agentId): string
{
return sprintf('%s.%s', $this->getKey(), $agentId);
}
}
View on GitHub (pinned to f0cf0a8b83)
Solutions
- Decode the embedded errcode/errmsg first
- Confirm the agentId still exists on the authorizer corp and matches the installed app version
- Refresh authorizer/suite tokens, clear the per-agent ticket key, then retry
- For freshly (re)installed apps, re-fetch after tokens settle instead of hammering retries
Defensive patterns
Strategy: try-catch
Validate before calling
if ($agentId <= 0) {
throw new \InvalidArgumentException('A valid numeric agentId is required for agent_config tickets.');
} Try / catch
try {
$ticket = $jsApiTicket->getAgentTicket($agentId);
} catch (\EasyWeChat\Kernel\Exceptions\HttpException $e) {
$payload = json_decode(strstr($e->getMessage(), '{') ?: '[]', true) ?: [];
// 40001-class → refresh authorizer/suite tokens then retry once; agent-missing errors → verify agentId
report($e);
} Prevention
- Validate that the agentId still exists on the corp before signing agent-config payloads
- Scope per-agent cache keys to the app version so reinstalled agents start clean
- Retry with backoff for freshly installed apps instead of tight loops
When it happens
Trigger: Running wx.agentConfig flows while the authorizer access token is invalid; the target agent (agentid) was deleted or the app version changed; suite credentials stale; a freshly reinstalled app whose tokens have not settled yet.
Common situations: Third-party WeChat Work apps signing agent-scoped JS-SDK after the authorizer changed or removed agents; stale per-agent cache entries surviving a reinstall; dev environments pointing at prod corp credentials.
Related errors
- Failed to get jssdk ticket: %s
- Failed to get jssdk ticket: %s
- Failed to get auth_corp_info: %s
- Failed to get access_token: %s
- Failed to get jssdk agentTicket: %s
AI-assisted analysis of w7corp/easywechat@f0cf0a8b83 (2026-08-21).
Data as JSON: /api/errors/63ba4d531bf50875.
Report an issue: GitHub.