javaunirestintercom

Unirest Java POST request for Intercom API return error 500


I'm currently trying to do a POST request on Intercom API using unirest for java and It returns a server error 500 but when I do the same request with Postman it returns my desired results.

Sample code:

Map<String, String> headers = new HashMap<>();
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer XXXXXXXXXXXXXXXXXXXXXXX");

HttpResponse response = Unirest
              .post("https://api.intercom.io/conversations/search")
              .headers(headers)
              .body(requestBody)
              .asObject(HashMap.class);

This is my request body

private Map<String, Object> getQueryValues(String field, String operator, Object value) {
    Map<String, Object> map = new HashMap<>();
    map.put("field", field);
    map.put("operator", operator);
    map.put("value", value);

    return map;
}

private Map<String, Object> getRequestBody() {
    List<Map<String, Object>> value = new ArrayList<>();
    value.add(getQueryValues("updated_at", ">", 1590278400));
    value.add(getQueryValues("source.delivered_as", "=", "admin_initiated"));

    Map<String, Object> query = new HashMap<>();
    query.put("operator", "AND");
    query.put("value", value);

    Map<String, Object> requestBody = new HashMap<>();
    requestBody.put("query", query);

    return requestBody;
}

Solution

  • The problem turns out to be my UNIX date long value wherein the correct value should be the Epoch seconds. So from myDate.getTime() I changed it to myDate.toInstant().getEpochSecond().