Scripting: Trying a category assign - returns "Bad Request" - Why

Started by ubacher, June 06, 2017, 11:56:45 AM

Previous topic - Next topic

ubacher

I created a new modal app.
I added code to assign the category IM-TEST to the selected files.
This code was copied from the categories sample app.

Running this app returns "400 Bad Request" via the error function.
What am I doing wrong?

PS: The category IM-TEST exists in my db!
Script attached as a .txt file

Mario

Check the response returned by IMWS. 400 Bad Request can mean a typo in your could, wrong parameters etc.
IMWS returns a detailed error message. You can see it in the Net tab of your browser, or you change your app to write the response to the console.

What does the error output on the console show?
Does the sample app work? If so, double-check your code.
Please understand that I cannot debug your scripts for you, sorry. No time.

Just checked the Categories sample script and it works. We need the precise error message to know more.
Check that IM-TEST exists and under  @All!
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

thrinn

The example needs a selection. If no file is selected when you make your call, you will get the error you described.
Thorsten
Win 10 / 64, IMatch 2018, IMA

ubacher

Thorston: Did you try running it. I did specify fileidlist: IMatch.idlist.fileWindowSelection

Here is what I found: If I run the script out of a browser window it works OK. If I run it thereafter within Imatch it works then also
but that may be because they categories are then already assigned.

If I change the selection and run again: fails.
Run it from the browser: no failure!

Mario: What could be the cause?


thrinn

I did not try to run your app, but the example categories app, because the code snippet is identical.
You can provoke a Bad Request response also in the example app with the advantage that it will print the complete response.

Try clicking on Assign Files while no file is selected in the file window. You will get:

400 (Bad Request)

{
  "error": {
    "code": 1102,
    "message": "Invalid parameter.",
    "details": {
      "parameter": "files",
      "description": "No files specified. Use the fileid, fileidlist or filepath parameter."
    }
  }
}


That's because IMatch.idlist.fileWindowSelection is specified but the selection in the file window (and, therefore, the idlist) ist empty.

Everything works fine if at least one file is selected.
Thorsten
Win 10 / 64, IMatch 2018, IMA

thrinn

OK, I now tried your example and also got an error. I added a statement to log the entire error object:

console.log('cat assign ' + error.status + ' ===' + error.statusText);
console.log(error);


The result is:

{
  "readyState": 4,
  "responseText": "{

\"error\":{

  \"code\":1011,

  \"message\":\"Insufficient privileges.\"

}

}",
  "responseJSON": {
    "error": {
      "code": 1011,
      "message": "Insufficient privileges."
    }
  },
  "status": 400,
  "statusText": "Bad Request"
}


But I have no idea why it works in the sample app. Can't find something about access privileges there.
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

I have downloaded the sample and copied it into a freshly created app.
I get an error. OK. IM-TEST does not exsit.
Create IM-TEST under @All. Make sure some files are selected. Run the script. Works. All images assigned.

IMWS does access privilege checks - this is required for a later IMatch WebViewer which can update the daabase.
But the user logged into IMatch always has all privileges.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

thrinn

Hm, after rebooting my PC it worked at first. Then again, after some (harmless) changes in the source code, it didn't. After several trial & error cycles I was able to reproduce the error.

- Create a fresh app using IMatch App Wizard. Only set the App name, all other settings on default.
- For example "My App 4"
- Open the app using the App Manager in one of the App Panels.
- Refreshing the app in the App Panel should do nothing, as expected. No errors so far.
- Now open the index.html in Visual Studio Code (while IMatch and the App are still running!)
- Copy the coding of the attachement into the index.html in Visual Studio Code and save. (The coding is the same as ubacher's, I only added two log statements.
- When IMatch picks up the change, you get the "Insufficient Privilege" errors.

- Now close & reopen the database --> App works successfully

I should mention that I set the internal browser cache to be cleared on exit.

Maybe some kind of authentication caching interferes with changing the source code of a running app?
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

Tried that. Works here.

I always modify apps currently loaded. Sometimes they are loaded in the app panel and an external web browser. Never saw this effect.
The IMatch user always has all privileges.
The IMatch class library automatically authenticates the user.

The only reason for this access privilege problem would be an invalid or authorized session.
Do you use a virus checker or something that may kick in when you save files?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

thrinn

I just created another app, following the steps of my previous post. Same result. And this time I had the virus checker explicitely disabled.

I will attache the log file if it is any help. But there is no error message, as far I can see, just infos "Authenticated".
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

No idea.
Never had that before, after using IMatch 2017 on three computers.
Need more info or a 100% repro case.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook