0

I am trying using an end point for updating a record, now that is working fine for postman, but it is not working for Unirest, as I have used everything. My code is like this:

    public static void updateTrialLength()throws IOException {
        String baseURL = whatever_URL_is;
        String path = "company/761";
        String url = baseURL + path;
        String token = getToken(username, password);
        Map<String, String> headers = new HashMap<>();
        headers.put("x-access-token", token);
        headers.put("accept", "application/json");
        String str = "{\"isTrial\":"+1+"}";
        JSONObject json = new JSONObject(str);
        try {
            HttpResponse<JsonNode> response = Unirest.put(url).header("x-access-token", token).
                    body(json).asJson();
            System.out.println(response.getBody());
        } catch (UnirestException e) {
            throw new IOException(e);
        }

    }

Now upon using this command, I have to change the value i.e. 'isTrial' is 0, and I have to update it to 1. I have used everything, its working at all. PostMan Result can be viewed from here. Its quiet frustrating now.

Taimoor Pasha
  • 192
  • 2
  • 3
  • 16
  • Can you post the result that you get? Also why do you add `"+1+"` (`"{\"isTrial\":"+1+"}"`) to the string instead of just putting it directly into the string? And instead of using plain json strings that you add to the json object I would recommend you adding things like: `json.put("fieldName", "fieldValue");` – CodeMatrix May 28 '22 at 16:56
  • I tried everything, yet still not working.@CodeMatrix – Taimoor Pasha May 31 '22 at 10:43
  • do have any updates like logs or errors or something like that? – CodeMatrix Jun 01 '22 at 10:19

0 Answers0