API Integration
The standard data interchange format of JSON makes using and integrating a REST API very easy in most modern programming languages.
Using Java
With Java here's how you could get your Agent API calls done
URL url = new URL("https://api.smarte.pro/v1/buying-group");
String req = "{\n" +
" \"companyName\": \"SMARTe\",\n" +
" \"pageNo\": 1,\n" +
" \"pageSize\": 10\n" +
"}";
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("apiKey", "76df567e-xxxx-xxxx-xxxxxxxxxxx");
httpURLConnection.setDoOutput(true);
try (OutputStream os = httpURLConnection.getOutputStream()) {
os.write(req.getBytes());
os.flush();
}
int responseCode = httpURLConnection.getResponseCode();
System.out.println("POST Response Code :: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
}
While Java doesn't have JSON support out of the box, there's plenty of libraries out there that can help with this.
For example, with Java EE or now Jakarta EE you could just use the JsonObject class to build your request.
JsonObject json =
Json.createObjectBuilder().add("companyName", "SMARTe").add("pageNo",1).add("pageSize",10).build();
Similarly, the response could also be read:
StringReader reader = new StringReader(httpResponse.body());
JsonObject responseJson = null;
try (JsonReader jsonReader = Json.createReader(reader)) {
responseJson = jsonReader.readObject();
System.out.println(responseJson);
}