FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important
information on the platform change.
11-01-2023 10:27 PM - edited 11-01-2023 10:28 PM
Hi all,
so I'm making good progress ... however with the Storage API I'm having a bit of trouble.
If I call the following url in the Swagger UI:
https://192.168.42.100/storage/api/v1/media
I get this response:
[ { "uuid": "C2E7-F514",
"label": "Extreme SSD",
"mounted": false,
"format": "exfat",
"size": 1000169226752,
"device": "sda1" }, { "uuid": "d2d26aa9-0ab9-4ecf-aff8-f8194080ee02",
"label": "ubuntu-data",
"mounted": true,
"format": "ext4",
"size": 2917068800,
"used": 1074192384,
"device": "mmcblk0p4",
"internal": true }, { "uuid": "4A65-4441",
"mounted": false,
"format": "fat32",
"size": 15633219584,
"device": "mmcblk1p1" } ]
I guess my "extreme" SSD should probably be an "extern" SSD (because that's what it is).
As you can see, I added an external USB SSD device as well as an micoSD card in the card reader slot.
The problem is, that I can't decode the response from the generated client as the "exfat" format is not specified in the spec. I'll probably manually add this in order to be able to continue, but I thought I'd report this, so it can be added to the list of constants.
Solved! Go to Solution.
11-01-2023 10:50 PM
Also does it list my external SSD and the microSD card as "unmounted". Now I would have expected that I could use the tasks api to mount them, however it looks as if the only option I have there seems to be to unmount them. Could someone tell me what the right process would be to use this API to mount them too?
11-02-2023 01:52 PM - edited 11-02-2023 01:55 PM
Hi,
Could you please clarify what you mean in your initial post by "the exfat format is not specified in the spec"? I see all of your devices returned a "format" key.
You should be able to mount devices using the storage api tasks endpoint. For whatever reason, this isn't included in the examples though.
POST to...
https://127.0.0.1:8443/storage/api/v1/tasks
Schema:
The call would then look like this...
{
"action": "mount",
"parameters": {
"media": "UUID",
"assignment": "data-exchange/storage-extension"
}
}
11-02-2023 02:14 PM
The example boxes of the Post-trials will be updated soon by the mount assignment. Please operate in the meantime with the schema infos or F12 Reverse-Engineering.
11-02-2023 02:25 PM
Hi,
in the OpenAPI json document the format of "exfat" is not included:
So my generated client didn't know how to parse that. I solved the problem by manually adding the constant to the generated class, but that's not an ideal solution. I guess if you just pass along unvalidated payloads in simple json or yaml structures, this doesn't matter, but as soon as something's strongly typed, that doesn't work. Also a bit odd that the server actually sends out responses that are not valid according to it's own specs.
And regarding the mounting, when looking at the Swagger UI, the only option I see in the UI, is "unmount". I usually try out the things I try in that and as I couldn't generate a "mount" command, I thought it wasn't supported. But looking into the details of TaskMount I'll simply book that under shortcoming of the Swagger UI.
Thanks,
Chris
11-02-2023 03:43 PM
So I've been trying to manually post requests to mount the devices, but the PLC keeps on responding with "400 bad request".
One version I tried, based on the documentation on the Swagger UI I tried this:
POST https://192.168.42.100/storage/api/v1/tasks
Content-Type: application/json
Accept: application/json
Authorization -> Bearer eyJhbGciOiJFUzM4N--- snip ---fvxWHsbqx5W3pZJ:
Content-Length: 106
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.8.1)
Accept-Encoding: br,deflate,gzip,x-gzip
{
"action":"mount",
"parameters":{
"media":"C2E7-F514",
"assignment":"storage-extension"
}
}
The "media" was the "UUID" of my removable device as returned by:
https://192.168.42.100/storage/api/v1/media
[
{
"uuid": "C2E7-F514",
"label": "Extreme SSD",
"mounted": false,
"format": "exfat",
"size": 1000169226752,
"device": "sda1"
},
{
"uuid": "4A65-4441",
"mounted": false,
"format": "fat32",
"size": 15633219584,
"device": "mmcblk1p1"
},
{
"uuid": "d2d26aa9-0ab9-4ecf-aff8-f8194080ee02",
"label": "ubuntu-data",
"mounted": true,
"format": "ext4",
"size": 2917068800,
"used": 1074720768,
"device": "mmcblk0p4",
"internal": true
}
]
The output the generated OpenAPI client would have produced was quite a bit different and the server didn't like it either:
{
"instance":{
"parameters":{
"media":"C2E7-F514",
"assignment":"storage-extension"
},
"action":"mount"
},
"isNullable":false,
"schemaType":"oneOf"
}
Help greatly appreciated.
11-02-2023 04:19 PM
The command below is working on my micro-SD in Ext4 format.
curl -X 'POST' \
'https://192.168.1.100/storage/api/v1/tasks' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTg5NjYxODQsImlhdCI6MTY5ODkzNzM4NCwiaWQiOiIxMDAwIiwibmFtZSI6ImJvc2NocmV4cm90aCIsIm5vbmNlIjoiNzU4NjU1MjQtM2Q3MC00YzNmLWExNDAtZTA1NzI5ZjBmOWFmIiwicGxjaGFuZGxlIjowLCJyZW1vdGVhdXRoIjoiIiwic2NvcGUiOlsicmV4cm90aC1kZXZpY2UuYWxsLnJ3eCJdfQ.ydKR7RzYQGrR8VOG4ZpY3aUAwT2yH1yOua8XpZdkypuVH5BtTW4cm0me6m9duZo1F3GH73siOOQD8kQaAkQOlRY4uCLF9I_Zq-t3sGA119r_wTjMslI8XpHe2Wic1Mns' \
-H 'Content-Type: application/json' \
-d '{
"action": "mount",
"parameters": {
"media": "91f34d0c-9859-42be-b945-d0eeaa805d8d",
"assignment": "data-exchange"
}
}'
Response:
{
"id": "2",
"state": "pending",
"eta": "2023-11-02T10:06:37.43626618-05:00",
"action": "mount",
"parameters": {
"assignment": "data-exchange",
"media": "91f34d0c-9859-42be-b945-d0eeaa805d8d"
},
"result": {
"type": "",
"title": ""
}
}
The 400 error makes it seem like your REST API request format is incorrect, although admittedly the error message isn't very helpful. I also think you will need to format your disc to Ext4 or Fat32.
11-02-2023 04:47 PM
Ok ... so thanks @Sgilk ... after copying line for line (of course using my UUID instead) I managed to find the problem ... in the bearer token line, the header was wrong. Not sure where the "->" came from, so that was what it was complaining about ... after changing that I got a successful task creation, however the task failed as it seems that "storage-extension" only works on encrypted storage, so I tried with "data-exchange" and that worked.