Hi,
So far no major hurdles implementing REST for tickets but the following has me stumped on the ConfigItem. I am interfacing our old cakePHP system into ITSM. And I can read a ConfigItem fine using:
http://ticket/otrs/nph-genericinterface ... sword=BLAH
When I try to do a search I always get:
ErrorMessage":"ConfigItemSearch: ConfigItem parameter is missing or not valid!
Looking at the debug it looks like the array is not being converted correctly.
$VAR1 = {
'ConfigItem%5BClass%5D' => 'Location',
'ConfigItem%5BName%5D' => 'N',
'Password' => 'XXXXXXX,
'RequestMethod' => 'GET',
'UserLogin' => 'jde.otrs'
};
I am hoping someone might be able to point me in the right direction and tell me where I am going wrong. Any help is really appreciated.
The cake PHP code is very simple.
$otrsCode['ConfigItem']['Class']='Location';
$otrsCode['ConfigItem']['Name']='N';
$httpSocket = new HttpSocket();
$sentUrl=$this->otrsUrl.'?UserLogin=jde.otrs&Password=XXXXXXXXXXXXXXX';
$response = $httpSocket->get($sentUrl,$otrsCode);
Thanks
Matt
[SOLVED] Generic Interface ConfigItem REST Search
Moderator: crythias
-
- Znuny newbie
- Posts: 4
- Joined: 12 Aug 2015, 01:29
- Znuny Version: 4.0.7
- Real Name: Matt Saint
- Company: Progility Technologies
[SOLVED] Generic Interface ConfigItem REST Search
Last edited by mattsaint on 12 Aug 2015, 15:50, edited 1 time in total.
-
- Znuny guru
- Posts: 2210
- Joined: 13 Mar 2014, 09:16
- Znuny Version: 6.0.14
- Real Name: Rolf Straub
Re: Generic Interface ConfigItem REST Search
I think this is the 3rd post asking about arrays over REST. No answer so far.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
-
- Znuny newbie
- Posts: 4
- Joined: 12 Aug 2015, 01:29
- Znuny Version: 4.0.7
- Real Name: Matt Saint
- Company: Progility Technologies
Re: Generic Interface ConfigItem REST Search
Perhaps best to move to Soap?
Matt
Matt
-
- Znuny newbie
- Posts: 4
- Joined: 12 Aug 2015, 01:29
- Znuny Version: 4.0.7
- Real Name: Matt Saint
- Company: Progility Technologies
Re: [SOLVED] Generic Interface ConfigItem REST Search
Hi,
I hope this helps someone else. I am not sure I fully understand the reasoning but it makes some sense.
Probably copying the Generic ConfigItem Rest example is not the best path forward. It uses POST to create a ticket and search uses GET.
On a bit of hunch I moved the update and create operations out to their own web service and changed the search operation to Post in Settings. This immediately changed my error and started complaining about decoding issues. Changing it to json_encode solved the final step.
I actually think the issue lies in the cakePHP httpSocket class and the encoding it does on the URL
Here is a GET
Incoming data before mapping (2015-08-13 00:02:52, debug)
Using json_encode($otrsData) on a get
Incoming data before mapping (2015-08-13 00:07:11, debug)
And finally Brining it all together in a POST with json_encode($otrsData)
Incoming data before mapping (2015-08-13 00:11:01, debug)
I would interested in other people's thoughts but it does look like arrays work fine in the rest interface provided you use POST. That makes sense really. Phew! there is a few hours I won't get back
I hope this helps someone else. I am not sure I fully understand the reasoning but it makes some sense.
Probably copying the Generic ConfigItem Rest example is not the best path forward. It uses POST to create a ticket and search uses GET.
On a bit of hunch I moved the update and create operations out to their own web service and changed the search operation to Post in Settings. This immediately changed my error and started complaining about decoding issues. Changing it to json_encode solved the final step.
I actually think the issue lies in the cakePHP httpSocket class and the encoding it does on the URL
Here is a GET
Code: Select all
$otrsData['ConfigItem']['Class']='Location';
$otrsData['UserLogin']=$this->otrsUser;
$otrsData['Password']=$this->otrsPass;
$httpSocket = new HttpSocket();
$sentUrl=$this->otrsUrl;
$response = $httpSocket->get($sentUrl,$otrsData);
debug ($response->code);
debug ( $response->body);
Incoming data before mapping (2015-08-13 00:02:52, debug)
Code: Select all
$VAR1 = {
'ConfigItem%5BClass%5D' => 'Location',
'Password' => 'xxx',
'RequestMethod' => 'GET',
'UserLogin' => 'jde.otrs'
};
Using json_encode($otrsData) on a get
Incoming data before mapping (2015-08-13 00:07:11, debug)
Code: Select all
$VAR1 = {
'%7B%22ConfigItem%22%3A%7B%22Class%22%3A%22Location%22%7D%2C%22UserLogin%22%3A%22jde.otrs%22%2C%22Password%22%3A%22xxxxD12JK2c%22%7D' => undef,
'RequestMethod' => 'GET'
};
Incoming data before mapping (2015-08-13 00:11:01, debug)
Code: Select all
$VAR1 = {
'ConfigItem' => {
'Class' => 'Location'
},
'Password' => 'xxx',
'UserLogin' => 'jde.otrs'
};
-
- Znuny newbie
- Posts: 4
- Joined: 12 Aug 2015, 01:29
- Znuny Version: 4.0.7
- Real Name: Matt Saint
- Company: Progility Technologies
Re: [SOLVED] Generic Interface ConfigItem REST Search
And just for completeness the final cakePHP function
Code: Select all
public function index(){
$otrsData['ConfigItem']['Class']='Location';
$otrsData['UserLogin']=$this->otrsUser;
$otrsData['Password']=$this->otrsPass;
$httpSocket = new HttpSocket();
$sentUrl=$this->otrsUrl;
$response = $httpSocket->post($sentUrl,json_encode($otrsData));
debug ($response->code);
debug ( $response->body);
$this->set('response_code', $response->code);
$this->set('response_body', $response->body);
}