"Note needs to have a content" Error When Posting Notes via API(JAVA)

Hi everyone,

I’m currently trying to integrate Pipedrive into my application and am encountering an issue when attempting to post notes via the API. Specifically, I’m receiving the following error message:

{
  "success" : false,
  "error" : "Note needs to have a content.",
  "error_info" : "Please check developers.pipedrive.com for more information about Pipedrive API.",
  "data" : null,
  "additional_data" : null
}

Here’s the relevant code I’m using:

Map<String, Object> result = new HashMap<>();

JSONObject queryParams = new JSONObject();
queryParams.put(PDConstants.QueryParamKeys.CONTENT, URLEncoder.encode(content, "UTF-8"));
queryParams.put(PDConstants.QueryParamKeys.DEAL_ID, Integer.parseInt(mapping.getCrmModuleId()));
queryParams.put(PDConstants.QueryParamKeys.PINNED_TO_DEAL_FLAG, 1);

JSONObject headerParams = new JSONObject();
headerParams.put("Authorization", "**MY_TOKEN**");
headerParams.put("Content-Type", "application/json");
headerParams.put("Accept", "application/json");

HttpRequestExecutor executor = HttpRequestBuilder.newBuilder().post().url(url).headers(headerParams).queryParams(queryParams).build();
HttpResponse response = executor.execute();
result = JungleUtil.toObj(response.getResponse(), Map.class);

Note: consider url, content and deal_id values are valid.

Despite providing the content parameter, I still receive the error indicating that it is missing.

Has anyone experienced this issue before? Any insights or suggestions on what I might be missing?

Thanks in advance for your help!

Hello There,

I can help you to find out this solution.can we discuss in detail.
Please share your availability to discuss over meeting or call so we xan share screen to see issue.

Thank you
Manisha

Hi Manisha,

Thank you for your initiative; I really appreciate it! I would love to connect for a screen-sharing session to discuss the details further. Before we set up a time, could you share what you think might have possibly gone wrong? This insight would help us make the most of our discussion.

Resolved the issue after providing with .rawData() in HttpRequestExecutor!!!

Below is the updated code for your reference:

Map<String, Object> result = new HashMap<>();

JSONObject queryParams = new JSONObject();
queryParams.put(content);
queryParams.put(PDConstants.QueryParamKeys.DEAL_ID, Integer.parseInt(mapping.getCrmModuleId()));
queryParams.put(PDConstants.QueryParamKeys.PINNED_TO_DEAL_FLAG, 1);

JSONObject headerParams = new JSONObject();
headerParams.put("Authorization", "**MY_TOKEN**");
headerParams.put("Content-Type", "application/json");
headerParams.put("Accept", "application/json");

HttpRequestExecutor executor = HttpRequestBuilder.newBuilder().post().url(url).headers(headerParams).rawData(queryParams.toString(), ContentType.TEXT_HTML.getMimeType()).build();
HttpResponse response = executor.execute();
result = JungleUtil.toObj(response.getResponse(), Map.class);

Purpose of .rawData()Setting Request Body

  1. Setting Request Body: This method allows you to provide the body content of the HTTP request directly as a string or byte array, rather than using a more structured format (like JSON or XML).
  2. Content Type Specification: By also passing the MIME type (like "text/html"), it informs the server about the type of data being sent, which is crucial for correct parsing and processing on the server side.