cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1576
Views
1
Helpful
8
Replies

Status Code 415

gmathilassi
Level 1
Level 1

Hello.

I`m trying to control a Global Cache Flex relay unit, via PUT command. I have used Insomnia to control the device, and it works fine from there. When I use Cisco to control this, I get an error back from the device. It looks like this:

16:23:35 [system] Using XAPI transport: WebSocket
16:23:35 [system] Starting macros...
16:23:35 GCTest Loading...
16:23:35 GCTest 'Script started'
16:23:35 GCTest 'Init started'
16:23:35 GCTest Ready!
16:23:40 GCTest 'GC1 Command_ON'
16:23:40 GCTest 'GC1 Command_SENT'
16:23:40 GCTest { code: 1,
data:
{ Headers:
[ { Key: 'Cache-Control', Value: 'max-age=600', id: '1' },
{ Key: 'Connection', Value: 'close', id: '2' },
{ Key: 'Content-Type', Value: 'application/json', id: '3' } ],
StatusCode: '415' },
message: 'Command returned an error.' }

I have also sent the commands in to a local webserver, in order to see what is sent from Cisco and from Insomnia. 

From Cisco:
Listening on port 80...
Received request for http://10.10.70.222/api/host/modules/1/relays/logicals/1
1---------------------
Content-Length, 38
Content-Type, application/json
Accept, */*
Accept-Charset, ISO-8859-1,utf-8
Host, 10.10.70.222
User-Agent, Cisco/CE
2---------------------
Content-Length
Content-Type
Accept
Accept-Charset
Host
User-Agent
3---------------------
{
"type": "SPST",
"state": "off"
}

 

From Insomnia

Listening on port 80...
Received request for http://localhost/api/host/modules/1/relays/logicals/1
1---------------------
Content-Length, 42
Content-Type, application/json
Accept, */*
Host, localhost
User-Agent, insomnia/2022.6.0
2---------------------
Content-Length
Content-Type
Accept
Host
User-Agent
3---------------------
{
"type": "SPST",
"state": "off"
}

 

They seems to be the same, but Cisco is also sending "Accept-Charset, ISO-8859-1,utf-8", while Insomnia is not. Is Cisco doing this automaticly? Or are there any way of stopping Cisco from sending this?

My code in Cisco:
const xapi = require('xapi');
console.log('Script started');
const GC_address = '10.10.70.140'; /* IP of GC flex. */
const HTTP_TIMEOUT = 1; /* How fast (in seconds) the HTTP get commands should fail with timeout error. */
const OutletMode = 4;


function GC1_On() {
var body = {
'type': 'SPST',
'state': 'off'
};

var header = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Length': 50
};


console.log('GC1 Command_ON');
var url = 'http://' + GC_address + '/api/host/modules/1/relays/logicals/1';


xapi.command('HttpClient Put', {
AllowInsecureHTTPS: true,
Url: url,
Header: ['Content-Type: application/json', "Accept: */*",]
},
JSON.stringify(body, undefined, 2)

).then((result) => {console.log(result.body)}).catch(e => console.log(e));

console.log('GC1 Command_SENT');
}

function onUiAction(event)
{
if (event.WidgetId === 'BlindClose' && event.Type === 'pressed')
{
GC1_On();
}
}

function init()
{
console.log('Init started');
xapi.config.set('HttpClient Mode', 'On'); //this needs to be set to on to allow HTTP Get
/* Event listeners for manual light controls from the touch 10 panel */
xapi.Event.UserInterface.Extensions.Widget.Action.on(onUiAction);
}

init();

 

8 Replies 8

gmathilassi
Level 1
Level 1

Hello.

I have tried to use Apiary API Mock server, and the commands came bak as OK. I look at the info both from my codec, and from Insomnia, and they was all the same. 

But when i try the same command on the real device, it comes back with error 415. I think i have to send an e-mail to Global Cache to raise a case at this thing.

If you want, you can have a look at the  results from APIary.

dstaudt
Cisco Employee
Cisco Employee

Testing your code, it seems the device (in my case a Webex registered Room Kit Plus) automatically adds the "accept-charset ISO-8859-1,utf-8 " header; further, it does not seem possible to override this by specifying something else in the HttpClient Put Header (e.g. 'accept-charset: *').
Accept-Charset is 'deprecated', however it is a valid header, and the value/charsets are valid.  It would be good if the device omitted this header entirely, however it's arguable that the GC API should handle this header gracefully (e.g. by ignoring it, or passing it for 'utf-8'.)
Assuming modifying the behaviour of the Cisco and/or GC device is the only fix, possibly the only workaround I can think of would be to establish a proxy server that strips the Accept-Charset header before forwarding it on.

Hello.

We have added this into Insomnia, and the GC is working there with accept-charset.
We have concluded that this doesn't make any issues.
I forgot to attach the link for GC Flex API.
https://gcapi.docs.apiary.io/#reference/relay-outputs/modify-type-or-state-attributes-of-a-logical-relay?console=1

We are using the relay module, and I just want to open and close the relay.
I have also tried to send this command via SSH on the codec:
xCommand HttpClient Get Url: http://10.10.70.140/api/host/modules/1/relays/logicals
However, this command successfully went through.
When I sent this, it came back with the same error message 415
xCommand HttpClient Put Header: "Content-Type: application/json" Url: http://10.10.70.140/api/host/modules/1/relays/logicals/1
{type:SPST,state:off}
.

I have no idea where to go from here.

Regards Glenn Mathilassi

Can you reproduce the problem by pointing your macro at the Apiary API's mock server, or only with the actual GC device?  Can you reproduce the problem with Postman or any other tool?
If all else fails, it would be helpful to compare network packet captures for requests from Cisco/Insomnia/(Postman)->GC

I did point it to Apiary API mock server, and then it came back as OK. When I changed it to the actual GC device, it got error 415. 

I have met now the same problem with same error. Amazing that this 415 error is so rare Cisco and iTach came here on one or two search result. After beating this up for some hours I believe that Cisco is blocking the "application/json" put action. Codec seems to destroy or ignore the header desire to use json and sends it as the wrong form, maybe only text. Attach to screenshot of wireshark capture. see that one from postman is recognized as HTTP/JSON while one from codec is only HTTP.

Postman to iTach:

postman to itach.png

And codec to a webserver (was unable to snoop the wire of codec to iTach so had to send the post to laptop webeserver. same laptop with postman.)

codec to webserver.png

 Is it it the correct conclusion that Cisco has hobbled the htttp client to not allow production of JSON content? Same seems to be the case for hex string that may be needed for similar process with GlobalCache itach rs232.


That should not be the case. Testing to a request bin site like webhook.site and doing xCommand HttpClient Put with content-type:application/json and a JSON body shows the JSON is properly received.

When I try to send it to Apirary Mock server, it works like a dream. But when I send it directly to GC, it returns 415 error. And the codes are the same, except address.