Bug in @imatch.selectedFolders ?

Started by Carlo Didier, November 04, 2018, 09:34:13 PM

Previous topic - Next topic

Carlo Didier

When I run this request from Powershell

Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/files?auth_token=&idlist=%40imatch.selectedFolders"

I get a file in the database which is neither currently displayed or selected nor in the currently open and selected folder in the "Media & Folders" panel.

Instead of the correct selected folder "D:\Photos\Photos Carlo\2018\10\2018-10-23 London", I get a reference to a jpg file: "D:\Photos\Photos Carlo\1995\1995 - Scotland\S6693.jpg"

Same thing if I directly enter the above URL in my browser.

thrinn

@imatch.selectedFolders represents a list of folders. I doubt that you can use this with the v1/files endpoint. If you use the v1/folders endpoint instead, you will get the correct result, but only the folder(s), not the files therein. It seems logical that v1/files only accepts idlists which represent files, not folders.

Thorsten
Win 10 / 64, IMatch 2018, IMA

Carlo Didier

Quote from: thrinn on November 04, 2018, 09:50:59 PM
@imatch.selectedFolders represents a list of folders. I doubt that you can use this with the v1/files endpoint. If you use the v1/folders endpoint instead, you will get the correct result

Ah, of course. Thanks Thorsten.
I'm having a hard time finding what I need in the doc. Especially when you want to use web requests. Except from the very rare example, I couldn't find an explanation of the complete syntax for such requests in the iMatch documentation. Hell, it's difficult enough to find anything (search is pretty useless and it's not even alphabetically sorted).

How for example would you translate something like this
IMatch.post('name of endpoint', ...)

into a web request? Where is this documented?

Attached is all I found about "selectedFolders" under idlist ... not much to go with.

Mario

#3
1. Please refer to the IMWS Documentation app, which is an integral part of IMatch.
It has examples for all endpoints. Most can be tried live, when IMatch is running!

2. When you run an IMatch app in your web browser while the developer tools <F12> are open, you can see the requests the app is making. Very informative.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

In the IMWS Documentation app, if I search for "files", I can't even find the method to return the selected files ...
And if I search for "select" or "selected", the result is nothing ...

Mario

QuoteI can't even find the method to return the selected files ...

Of course not. IMWS has no concept of selected files. IMWS is independent from IMatch, it works also in IMatch Anywhere and other contexts! It does not need IMatch to run.

Many endpoints for working with files take either a list of file ids, an idlist (a list of file ids managed by IMWS or IMatch) or a list of paths.
IMatch offers the list of files selected in the active file window in the idlist named @imatch.filewindow.active.selection.

This means that when you want to get info about some files, you can use the idlist parameter for the v1/files endpoint and specify it as

idlist : '@imatch.filewindow.active.selection'

IMatch offers a bunch of other idlists, e.g. for finding the focused file, all selected folders etc.  For example, to get info about all selected folders you use the v1/folders endpoint, and specify idlist: '@imatch.selectedFolders'

The names of the idlists are conveniently wrapped by the IMatchLib helper class and documented there as well.

Example: Fetch the id and name of all files selected in the file window:



This is the request the browser is sending to IMatch (from the developer tools in my web browser):

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

I can get the selected files already. Found that out with an example you gave me.

But I still don't know how to find out how to add an image to a category for example.
There is no explanation of the http syntax to use in such a case. Or are http requests limited to queries? Is it impossible to change anything through http?

Mario

#7
Please look again at the documentation for IWMS.



Then use the categories example app to see how files are assigned and unassigned.

If you want to transfer that to a PowerShell script, run the app in your browser and look at the http requests made when assigning and unassigning files. You can directly transfer that to PowerShell via copy/paste. You need to make a POST request of course, not GET.

The browser shows the URL as http://127.0.0.1:50519/v1/categories/assign and the parameters are sent as part of the post body ("form data") as required for POST requests:

path: IM-TEST
fileidlist: @imatch.filewindow.active.selection
auth_token: ...

This assigns all files selected in the file window to the IM-TEST category.


-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

As I said, I have never before used web requests from a script, so I know nothing about how to do them correctly and I couldn't find it out from the iMatch doc.

I tried to find out the id of a category, but I can't get a result from any of these:
Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/categories?auth_token=&path=@All|_Notes"
Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/categories?auth_token=&path='@All|_Notes'"
Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/categories?auth_token=&path='%40All|_Notes'"
Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/categories?auth_token=&path=%40All|_Notes"


The result always returns an empty collection:
StatusCode        : 200
StatusDescription : OK
Content           : {"categories":[]}


As for posting, from googling, I found a bit more and tried this:
Invoke-WebRequest -UseBasicParsing "http://127.0.0.1:50519/v1/categories/assign?auth_token" -ContentType "application/json" -method POST -body "{'id':100, 'fileid':116778}"

result:
Invoke-WebRequest : The remote server returned an error: (400) Bad Request.

I tried different variations, but I don't have a clue what the correct syntax should be ...

David_H

Quote from: Carlo Didier on November 05, 2018, 04:20:14 PM
As I said, I have never before used web requests from a script, so I know nothing about how to do them correctly and I couldn't find it out from the iMatch doc.

I tried to find out the id of a category, but I can't get a result from any of these:
Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/categories?auth_token=&path=@All|_Notes"
Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/categories?auth_token=&path='@All|_Notes'"
Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/categories?auth_token=&path='%40All|_Notes'"
Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/categories?auth_token=&path=%40All|_Notes"


You don't have the @All in the path, unless its just @All
path (optional: true)
One or more fully qualified paths separated by , for the categories to retrieve, in standard IMatch syntax without the leading @All: parent|child. If the category name contains a comma, it must be escaped with a tilde ~ => ~,


So it should be something like
invoke-webrequest -Uri "http://localhost:50519/v1/categories?auth_token=&path=Places|UK|England"


Returning:

StatusCode        : 200
StatusDescription : OK
Content           : {"categories":[{"id":1347,,.......


Carlo Didier

Thanks David!
One of the examples in the iMatch WebServices doc said
http://127.0.0.1:50519/v1/categories?{auth}&​path=@All|location|london
so I thought I had to give the whole path starting with "@All"

Mario

I have fixed this typo, thanks. Appeared only once. The documentation of the path parameter is correct:

QuoteOne or more fully qualified paths separated by , for the categories to retrieve, in standard IMatch syntax without the leading @All.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

I still can't find out how to assign a file to a category through http ...

Mario

I showed you in the other thread. Make a POST request, it cannot be done with GET of course.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Google gave me an example for a post and I tried this:
Invoke-WebRequest -UseBasicParsing "http://127.0.0.1:50519/v1/categories/assign?auth_token=" -ContentType "application/json" -Method POST -Body "{ 'id':21314, 'fileid':116775}"

but I only get this:
Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
At \\LOCHMAREE\MyDocs_Carlo\My Programs\iMatch\libIMFunctions.ps1:67 char:1
+ Invoke-WebRequest -UseBasicParsing "http://127.0.0.1:50519/v1/categor ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand


Th IDs are correct.

Mario

Look at the response returned by IMWS for more info about the error.
You need to supply an auto_token, for a start. Even if it is empty.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

David_H

Quote from: Carlo Didier on November 06, 2018, 04:29:35 PM
Google gave me an example for a post and I tried this:
Invoke-WebRequest -UseBasicParsing "http://127.0.0.1:50519/v1/categories/assign?auth_token=" -ContentType "application/json" -Method POST -Body "{ 'id':21314, 'fileid':116775}"

Th IDs are correct.

They don't go in the body; they are parameters to the request.

invoke-webrequest -Method POST -Uri "http://localhost:50519/v1/categories/assign?auth_token=&id=287&fileid=163838"

Or, in your case

invoke-webrequest -Method POST -Uri "http://localhost:50519/v1/categories/assign?auth_token=&id=21314&fileid=116775"

Carlo Didier

Quote from: Mario on November 06, 2018, 06:11:29 PM
Look at the response returned by IMWS for more info about the error.
What I put in my previous post is all the response I get.

Quote from: Mario on November 06, 2018, 06:11:29 PM
You need to supply an auto_token, for a start. Even if it is empty.
Didn't I do that with "auth_token="?

Carlo Didier

Quote from: David_H on November 06, 2018, 07:27:01 PM
invoke-webrequest -Method POST -Uri "http://localhost:50519/v1/categories/assign?auth_token=&id=21314&fileid=116775"
That's the solution! Thanks David!
As always, it's a matter finding the correct information  :)