Hi, we are trying to create tickets in ConnectWise manage usnig the new Media Type Webhook feature. I have a successful get request (based on looking though other integrations and trying to minimise the code down) but cannot get a successful post.
Here is my code:
and this is the error returned when testing the media type:
"code": "ConnectWiseApi",
"message": "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ConnectWise.Apis.v3_0.v2015_3.Service.Ticket.Tick et' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '', line 1, position 1."
So the message is fairly obvious but I cannot figure out how to get this right. I've tried 'one line-ing' the data and formatting as described above, but that made no difference.
Also trying to google for new httprequest() is not that helpful; most results are for xmlhttpresquest or fetch neither of which appeared to work for the media type.
Is someone help me out with this pleeeeease?
Here is my code:
Code:
try {
Zabbix.log(4, '[ CWMTest webhook ] Started with params: ' + value);
var result = {
'tags': {
'endpoint': 'cwm'
}
},
params = JSON.parse(value),
req = new HttpRequest(),
//fields = {},
resp;
if (params.HTTPProxy) {
req.setProxy(params.HTTPProxy);
}
req.addHeader('Content-Type: application/json');
req.addHeader('Authorization: Basic ' + params.authentication);
req.addHeader('clientId: ' + params.clientid);
var data = {
summary: 'test',
recordType: 'ServiceTicket',
initialDescription: 'test description',
board: {
name: 'IT RMM'
},
};
JSON.stringify(data);
resp = req.post(params.url, data);
resp = JSON.parse(resp);
Zabbix.log(4,(resp));
result.tags.issue_id = resp.id;
result.tags.issue_key = resp.key;
return JSON.stringify(resp);
}
catch (error) {
Zabbix.log(3, '[ CWM test webhook ] issue creation failed : ' + error + resp);
throw 'Failed with error: ' + error;
}
"code": "ConnectWiseApi",
"message": "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ConnectWise.Apis.v3_0.v2015_3.Service.Ticket.Tick et' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '', line 1, position 1."
So the message is fairly obvious but I cannot figure out how to get this right. I've tried 'one line-ing' the data and formatting as described above, but that made no difference.
Also trying to google for new httprequest() is not that helpful; most results are for xmlhttpresquest or fetch neither of which appeared to work for the media type.
Is someone help me out with this pleeeeease?
Comment