gpt4 book ai didi

java - 如何使用 API 在 ZOHO INVOICE 中添加新客户?我使用以下 POST 方法创建新客户..但我不会工作

转载 作者:行者123 更新时间:2023-12-02 03:26:38 24 4
gpt4 key购买 nike

HttpClient httpClient = new DefaultHttpClient();

try {
HttpPost request = new HttpPost("https://invoice.zoho.com/api/v3/contacts?authtoken="ur_token"&organization_id="ur_org_id");
StringEntity params =new StringEntity("JSONString={\"contact_name\":\"company_name\",\"age\":\"20\"} ");
request.addHeader("content-type", "application/json");
request.addHeader("Accept","application/json");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
System.out.println(response);

// handle response here...
}catch (Exception ex) {
// handle exception here
} finally {
httpClient.getConnectionManager().shutdown();
}

如何使用 API 在 ZOHO INVOICE 中添加新客户?我使用以下 POST 方法创建新客户,但它不起作用。

最佳答案

我希望下面的代码能够满足您的需求。

HttpClient httpClient = HttpClientBuilder.create().build();
String url = "https://invoice.zoho.com/api/v3/contacts?authtoken=AUTHTOKEN&organization_id=ORGID";
HttpPost request = new HttpPost(url);

JSONObject json = new JSONObject();
json.put("contact_name", "Test");
//You can add other JSONString params here.

List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("JSONString", json.toString()));
//You can add other params like JSONString here.

request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
request.addHeader("Accept", "application/json");
HttpResponse response = httpClient.execute(request);

ResponseHandler<String> handler = new BasicResponseHandler();

System.out.println(response.getStatusLine().getStatusCode());
String body = handler.handleResponse(response);

System.out.println(body);

关于java - 如何使用 API 在 ZOHO INVOICE 中添加新客户?我使用以下 POST 方法创建新客户..但我不会工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38781470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com