02-16-2020 03:46 AM
Hello
I have an item of equipment on a system and I need to send commands and read data to and from it.
I have been told it uses HTTP/JSON-RPC API.
So I don't know what I don't know here! and I need some 'get out of the box' help if possible.
I have attached a screenshot hopefully which will explain all.
Many thanks in advance
Lee
Solved! Go to Solution.
02-16-2020 06:17 AM - edited 02-16-2020 06:18 AM
Hi Lee,
If you're confident with the JSON string, you might simplify your initial testing by removing the Flatten to JSON node. Probably in the long run you'll want to use this to allow easier manipulation of the input (rather than having to specify a string) but to get started I'd suggest as few moving parts as possible.
After that, I'd try maybe using a POST request rather than PUT + GET. I'm not certain this will help, but I think it might give you something different to look at at least.
The GET result is returning the same as your Chrome browser, because that's the default request type when you browse to a website. Unfortunately, it doesn't appear that the GET type is supported in that URL edit: I'd say more accurately it is supported (because you got something back) but it isn't the method you want (hence the suggestion to try POST). The PUT method appears to be unsupported.
02-22-2020 12:30 AM
Good morning,
Thank you for your reply and what you describe is along the same lines as the reponse from the manufacturer, see below. So it looks as if it needs some header information, there is a header section of vi's in the palette but i cant see how to include as it looks like i need to use some handle vi's as well? Im still somewhat confused. Many thanks in advance if you can help.
Looking at your pictures I think the issue is with the HTTP request contents. We didn't document that as this header information it's normally handled by the libraries used when using a conventional programming language. I will add some information to the document on this but to help now an example HTTP request header with json-rpc body is given below:
============================
POST /api1 HTTP/1.1
Host: 192.168.201.46
Content-Type: application/json-rpc
Content-Length: 87
{"id": "b972f1d8-3ef4-429f-b5ca-88e42ef95cae", "method": "getStatus", "jsonrpc": "2.0"}
============================
So I think the main differences are:
02-22-2020 03:29 AM
Hi again,
So for the headers, I think that yes - you do need a handle.
You can create one using the HTTP library's "OpenHandle.vi" - note that none of the inputs are required (this initially caught me out).
Then you can add headers (there's a dropdown if you Create Constant, but you can type whatever you want there) using the AddHeader.vi.
Here's an image of an example (several VIs):
You can see that I have a session reference stored in an FGV here (you could create one each time, but I need to store some additional information and it's easier for me to do this just once every now and again) and that I call the FGV with the POST action and a bunch of data from my "Create Payload.vi". This is used in the POST Multipart node, but you could use something simpler if you don't need this.
02-24-2020 04:11 AM
I seem to get a response now, but unsure if I am correctly setting the header. A picture tells a thousand words so I have attached a screenshot.
02-24-2020 06:42 AM
The screenshot looks reasonable to me.
@LeeBowers1 wrote:
I seem to get a response now, but unsure if I am correctly setting the header. A picture tells a thousand words so I have attached a screenshot.
Is the response what you expect? And of so, does anything appear not to be working?
If not, seems like your problem is solved.
If there's still some issue/unexpected behaviour, feel free to let me/us know what it is and I/the forum can try and give further advice.
02-24-2020 07:04 AM
Hello again, thank you for replying
These are the results we could get
Response when ok:
{"jsonrpc":2.0,"id":0,"result":null}
Response when error:
{“jsonrpc”:”2.0”, “id”: 0, “error”:{“code”: -32601, “message”: “Unknown method”}}
as we are getting the error response i suspect we are still not sending the header or something correctly. It is like we are almost there but not quite ...
02-24-2020 08:26 AM
Hello,
I now have the unit responding correctly. I was incorrectly using the unflatten to json function. Bit of a mixture of sending a string in the json format and then also using the unflatten to json as well!
Many thanks for your helps and replies.
Lee