binarywang/WxJava · error · WxRuntimeException

更新「联系我」方式需要指定configId

Error message

更新「联系我」方式需要指定configId

What it means

Thrown as WxRuntimeException (unchecked) inside updateContactWay when the WxCpContactWayInfo's configId is blank. The configId is the unique identifier returned by WeChat when a 'contact me' way is first created; without it the update API has no target to modify. This is a client-side precondition check that fires before any HTTP request is sent.

Source

Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java:82

    final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CONTACT_WAY);
    return WxCpContactWayInfo.fromJson(this.mainService.post(url, json.toString()));
  }

  @Override
  public WxCpContactWayList listContactWay(Long startTime, Long endTime, String cursor, Long limit) throws WxErrorException {
    JsonObject json = new JsonObject();
    json.addProperty("start_time", startTime);
    json.addProperty("end_time", endTime);
    json.addProperty("cursor", cursor);
    json.addProperty("limit", limit);
    final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_CONTACT_WAY);
    return WxCpContactWayList.fromJson(this.mainService.post(url, json.toString()));
  }

  @Override
  public WxCpBaseResp updateContactWay(WxCpContactWayInfo info) throws WxErrorException {
    if (StringUtils.isBlank(info.getContactWay().getConfigId())) {
      throw new WxRuntimeException("更新「联系我」方式需要指定configId");
    }
    if (info.getContactWay().getUsers() != null && info.getContactWay().getUsers().size() > 100) {
      throw new WxRuntimeException("「联系我」使用人数默认限制不超过100人(包括部门展开后的人数)");
    }

    final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_CONTACT_WAY);

    return WxCpBaseResp.fromJson(this.mainService.post(url, info.getContactWay().toJson()));
  }

  @Override
  public WxCpBaseResp deleteContactWay(String configId) throws WxErrorException {
    JsonObject json = new JsonObject();
    json.addProperty("config_id", configId);

    final String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEL_CONTACT_WAY);

    return WxCpBaseResp.fromJson(this.mainService.post(url, json.toString()));

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Call getContactWay(configId) or listContactWay first to retrieve the existing contact way info that already has configId populated, modify its fields, then pass it to updateContactWay.
  2. If you have the configId string already, set it explicitly: info.getContactWay().setConfigId(configId) before calling updateContactWay.
  3. Verify the configId is not null/blank with StringUtils.isNotBlank(info.getContactWay().getConfigId()) before invoking updateContactWay.

Example fix

// before
WxCpContactWayInfo info = new WxCpContactWayInfo();
info.getContactWay().setUsers(new ArrayList<>(users));
service.updateContactWay(info); // throws - configId is null

// after
WxCpContactWayInfo info = service.getContactWay(configId);
info.getContactWay().setUsers(new ArrayList<>(users));
service.updateContactWay(info);
Defensive patterns

Strategy: validation

Validate before calling

if (info == null || info.getContactWay() == null || StringUtils.isBlank(info.getContactWay().getConfigId())) {
    throw new IllegalArgumentException("configId is required for updateContactWay");
}

Try / catch

try {
    service.updateContactWay(info);
} catch (WxRuntimeException e) {
    if (e.getMessage().contains("configId")) {
        // handle missing configId: retrieve existing config first
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling cpService.getExternalContactService().updateContactWay(info) where info.getContactWay().getConfigId() returns null, empty, or whitespace. Typically happens when constructing a new WxCpContactWayInfo from scratch instead of first calling getContactWay(configId) to retrieve the existing record.

Common situations: Developer builds a WxCpContactWayInfo object for updating but forgets to set the configId returned from the original addContactWay call. Or they pass the same object used for addContactWay (which does not have a configId yet) to updateContactWay.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/e95f54a53c5a605c. Report an issue: GitHub.