Hello,
If there is no attached file, a Tracker Ticket is created normally.
However, if I try to include the attachment, I still get the datatype_mismatch error.
This error is occurs when a request is made to multipart/form-data.
Please help me how to use related_ticket_ids with attachments.
I attached my test code.
[Errors]
{"description":"Validation failed","errors":[{"field":"related_ticket_ids","message":"Value set is of type String.It should be a/an Array","code":"datatype_mismatch"}]}
{"description":"Validation failed","errors":[{"field":"related_ticket_ids","message":"It should contain elements of type Positive Integer only","code":"datatype_mismatch"}]}
============
java test
private Object request(String api, HttpMethod method, HttpEntity body) throws IOException, URISyntaxException {
URL targetUrl = new URL(config.getFreshdeskEndPoint() + api); // URL object from API endpoint:
return RestApiUtil.request(targetUrl.toString(), method, body);
}
public JSONObject createTicket(JSONObject data, List<FreshdeskAttachment> attachments) throws IOException, URISyntaxException {
HttpEntity entity = null;
if (attachments == null) {
entity = new StringEntity(data.toString(), ContentType.APPLICATION_JSON.withCharset(Charset.forName(UTF8)));
} else {
MultipartEntityBuilder meb = MultipartEntityBuilder.create();
meb.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
for (String key : data.keySet()) {
if (FreshdeskTicketField.CustomFields.equals(key)) {
JSONObject custom_f = new JSONObject(data.optString(key));
for (String key1 : custom_f.keySet()) {
meb.addTextBody(FreshdeskTicketField.CustomFields + "[" + key1 + "]", custom_f.optString(key1), ContentType.MULTIPART_FORM_DATA.withCharset(UTF8));
}
} else if (FreshdeskTicketField.Tags.equals(key)) {
JSONArray tagArray = data.getJSONArray(FreshdeskTicketField.Tags);
//meb.addTextBody(FreshdeskTicketField.Tags, "[]"); //if list is empty
if (tagArray != null && tagArray.length() > 0) {
for (int i = 0; i < tagArray.length(); i++) {
meb.addTextBody(FreshdeskTicketField.Tags + "[]", tagArray.optString(i), ContentType.MULTIPART_FORM_DATA.withCharset(UTF8));
}
}
} else if (FreshdeskTicketField.RelatedTicketIds.equals(key)) {
JSONArray idArray = data.getJSONArray(FreshdeskTicketField.RelatedTicketIds);
if (idArray != null && idArray.length() > 0) {
for (int i = 0; i < idArray.length(); i++) {
meb.addTextBody(FreshdeskTicketField.RelatedTicketIds + "[]", idArray.optString(i), ContentType.MULTIPART_FORM_DATA.withCharset(UTF8));
}
}
} else if (FreshdeskTicketField.CcEmails.equals(key)) {
JSONArray ccEmailsArray = data.getJSONArray(FreshdeskTicketField.CcEmails);
if (ccEmailsArray != null && ccEmailsArray.length() > 0) {
for (int i = 0; i < ccEmailsArray.length(); i++) {
meb.addTextBody(FreshdeskTicketField.CcEmails + "[]", ccEmailsArray.optString(i), ContentType.MULTIPART_FORM_DATA.withCharset(UTF8));
}
}
} else {
meb.addTextBody(key, data.optString(key), ContentType.MULTIPART_FORM_DATA.withCharset(UTF8));
}
}
addFileEntity(meb, attachments);
entity = meb.build();
}
return (JSONObject) request(String.format("/api/v2/tickets"), HttpMethod.POST, entity);
}