【问题标题】:Zoho Rest Invoice API Return 400 Error, Java HttpClientZoho Rest Invoice API 返回 400 错误,Java HttpClient
【发布时间】:2020-01-20 12:37:33
【问题描述】:

我想在我的 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\":{\"attention\":\"Jay \",\"地址\":\"${地址}\",\"city\":\"INDORE\",\"country\":\"India\",\"phone\":9xxxxxxxxx} ,\"shipping_address\":{\"注意\":\"Jay\",\"address\":\"${address}\",\"city\":\"INDORE\",\"country \":\"印度\",\"电话\":9xxxxxxxxx}}"

提前致谢!

【问题讨论】:

    标签: java spring-boot invoice zoho


    【解决方案1】:

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

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

    这造成了一个问题。

    问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多