photools.com Community

IMatch Discussion Boards => IMatch Scripting and Apps => Topic started by: ubacher on September 06, 2017, 02:32:25 PM

Title: v1/files/move - response missing or??
Post by: ubacher on September 06, 2017, 02:32:25 PM
IMWS.post('v1/files/move' ...
does not seem to return a response.

And: it would be good if the response could indicate if the file ( existed) and was replaced or not.
Title: Re: v1/files/move - response missing or??
Post by: Mario on September 06, 2017, 05:24:47 PM
The response is HTTP status code 200 OK if the operation is successful, else a HTTP 500 with additional info. Try to move a non-existing file.

The result depends on what you specify for the replace parameter.
You can easily tell if the target file already existed. Or use the filesystem/files/info endpoint to determine if a file exists in advance.
Title: Re: v1/files/move - response missing or??
Post by: ubacher on September 06, 2017, 10:33:29 PM
I use the following code:
IMWS.post('v1/files/move', {
                        idlist: IMatch.idlist.fileWindowSelection,
                        target: folderName,
                        replace: 'makeunique'
                    }).then(function (responseM) {
                        if (responseM.result == 'ok') {
                          }
                        else {
                            alert('move to pano ' + JSON.stringify(responseM, null, 2));
                        }
                    },
                        function (error) {
                            alert('file move error ' + error.status + ' ===' + error.statusText);
                        }
                        )

I get the alert showing: move to pano {}
The debugger shows responseM to be an object, responseM.result undefined.
The move takes place however!
Title: Re: v1/files/move - response missing or??
Post by: thrinn on September 07, 2017, 08:44:22 AM
My understanding is: There is no need for an explicit "result == 'ok'" because the Promise returned by the endpoint only resolves (-> "then" part) if everything worked ok. If there is an error the Promise is rejected, meaning only the reject part (your function (error)) is executed. In this case, the error parameter contains additional information about what kind of error happened.
Title: Re: v1/files/move - response missing or??
Post by: Mario on September 07, 2017, 10:31:51 AM
Correct.
The then function is only executed by JS when the server returned 200OK. Else it will call the error function. So:

IMWS.post('v1/files/move', {}).then(function()) {
  // Yay! Worked.
}
,function(error) {
// Oops. Check error for error codes and details.
});