You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用TeamTailor API的POST方法遇异常:候选人创建后流程受阻

TeamTailor API 候选人创建与职位关联异常问题

我正在实现两个基于TeamTailor API的方法:一个用于在TeamTailor系统中创建候选人,另一个用于将该候选人关联至指定职位申请。

调试过程中发现:执行创建候选人的方法时,生成响应阶段会抛出异常;打印请求体可得到包含错误信息的JSON,但使用Postman发送相同请求时,能返回201状态码,候选人可成功创建。

核心问题

  • 即便抛出异常,候选人仍会被创建;
  • 由于创建候选人的方法抛出异常,后续无法调用关联职位的方法。

同时调试时还出现错误提示:

Must use either different key or iv for GCM encryption

相关方法代码

createCandidateUniRest方法

private String createCandidateUniRest(String nome, String cognome, String email) throws UnirestException {
    Unirest.setTimeouts(0, 0);
    HttpResponse<String> response = Unirest.post("https://api.teamtailor.com/v1/candidates")
            .header("Authorization", "Token token=" + authToken)
            .header("X-Api-Version", "20210218")
            .header("Content-Type", "application/vnd.api+json")
            .body("{\"data\": {\"type\": \"candidates\",\"attributes\": {\"first-name\": \"" + nome + "\",\"last-name\": \"" + cognome + "\",\"email\": \"" + email + "\"}}}")
            .asString();

    JSONObject jsonResponse = new JSONObject(response.getBody());
    String candidateId = jsonResponse.getJSONObject("data").getString("id");

    return candidateId;
}

createJobApplication方法

public Response createJobApplication(String nome, String cognome, String email) throws CandidateCreationException {

    String candidateId = "";

    try {
        candidateId = createCandidateUniRest(nome, cognome, email);
    } catch (UnirestException e) {
        throw new RuntimeException(e);
    }

    OkHttpClient client = new OkHttpClient().newBuilder().build();
    MediaType mediaType = MediaType.parse("application/vnd.api+json");
    JsonObject data = new JsonObject();
    JsonObject attributes = new JsonObject();
    attributes.addProperty("cover-letter", "");
    attributes.addProperty("sourced", true);
    attributes.addProperty("send-user-notifications", true);
    data.add("attributes", attributes);
    JsonObject candidate = new JsonObject();
    candidate.addProperty("type", "candidates");
    candidate.addProperty("id", candidateId);
    JsonObject relationships = new JsonObject();
    relationships.add("candidate", candidate);
    JsonObject job = new JsonObject();
    job.addProperty("type", "jobs");
    job.addProperty("id", jobId);
    relationships.add("job", job);
    data.add("relationships", relationships);
    data.addProperty("type", "job-applications");
    JsonObject jobApplication = new JsonObject();
    jobApplication.add("data", data);
    RequestBody body = RequestBody.create(mediaType, jobApplication.toString());
    Request request = new Request.Builder()
            .url("https://api.teamtailor.com/v1/job-applications")
            .method("POST", body)
            .addHeader("Authorization", "Token token=" + authToken)
            .addHeader("X-Api-Version", "20210218")
            .addHeader("Content-Type", "application/vnd.api+json")
            .build();
    try {
        Response response = client.newCall(request).execute();
        return response;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

内容的提问来源于stack exchange,提问作者FOCS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 19:43:17