首页 > 解决方案 > Zoho Rest Invoice API 返回 400 错误,Java HttpClient

问题描述

我想在我的 Spring 应用程序中集成 Zoho Invoice API。我已经AuthToken成功整合了一部分。现在我正在使用创建联系人 API。但 API 返回错误 400。

我正在使用以下代码:

public String processZohoRequest(String apiUrl,Map<String, String> params,String method, String auth) throws UnsupportedEncodingException, IOException {
    URL url = new URL(apiUrl);
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod(method);

    if(!AppUtility.isEmpty(auth)) {
        con.setRequestProperty("Authorization", auth);
        con.setRequestProperty("Content-Type", "multipart/form-data");
        con.setRequestProperty("X-com-zoho-invoice-organizationid", testZohoOrgId);
    }

    if(!AppUtility.isEmpty(params)) {
        con.setDoOutput(true);
        DataOutputStream out = new DataOutputStream(con.getOutputStream());
        out.writeBytes(ParameterStringBuilder.getParamsString(params));
        out.flush();
        out.close();
    }
    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer content = new StringBuffer();
    while ((inputLine = in.readLine()) != null) {
        content.append(inputLine);
    }
    in.close();
    con.disconnect();

    return content.toString();
}

我使用 sam 方法来获取正在工作的访问令牌,但是当使用它来创建联系人时它返回错误。谁能告诉我如何解决这个问题?

`API-URL`: https://invoice.zoho.com/api/v3/contacts

json String:"{\"contact_name\":\"Jay Panjwanai\",\"company_name\":\"Ozone\",\"billing_address\":{\"注意\":\"Jay \",\"地址\":\"${address}\",\"city\":\"INDORE\",\"country\":\"India\",\"phone\":9xxxxxxxxx},\"shipping_address\" :{\"注意\":\"Jay\",\"地址\":\"${地址}\",\"城市\":\"INDORE\",\"国家\":\"印度\",\"电话\":9xxxxxxxxx}}"

提前致谢!

标签: javaspring-bootinvoicezoho

解决方案


好吧,在与他们的支持团队讨论后,我得到了答案。只需删除以下行:

con.setRequestProperty("Content-Type", "multipart/form-data");

这造成了一个问题。

问候


推荐阅读