Can't create a new lead using the API with Java
Hello,
i use this code to create a new lead using java
String url = "https://api.insight.ly/v2.3/";
URL object = new URL(url);
HttpURLConnection con = (HttpURLConnection) object.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
String Auth = "mykey";
con.setRequestProperty("Authorization", Auth);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept-Encoding", "gzip");
con.setRequestMethod("POST");
JSONObject Lead = new JSONObject();
Lead.put("last_name", "kemoz");
Lead.put("first_name", "amr2025");
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream(), "utf-8");
wr.write(Lead.toString());
wr.flush();
StringBuilder sb = new StringBuilder();
int HttpResult = con.getResponseCode();
if (HttpResult == HttpURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(
new InputStreamReader(con.getInputStream(), "utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
System.out.println("" + sb.toString());
} else {
out.println("Code = " + HttpResult);
System.out.println("Error else \n" + con.getResponseMessage());
}
i got HTML code and when i go check the leads i did not find the new lead i create i get no error code from this request so what i did wrong let me can't create a new lead
Update this the return file i got when i use this function
download it from http://s000.tinyupload.com/?file_id=72748720877554322062
Thanks
Comments
Hello amr kamal,
The endpoint for creating a lead using API v2.3 is https://api.insight.ly/v2.3/Leads. If you omit the "Leads" part, you are going to our API documentation page, which is the reason why you received the HTML response.
Please let us know if you have any further questions.
Thanks!
Thank you i solve it
Post is closed for comments.