Hi, I am trying access api from other web application (via javascript) but I have permission problems…
How I can make ajax request to gallery app (to get list files for example). What I need send to request (or header) to api automatically make login and return files as json to me? The Document API not is clean to me.
Thank you!
Which error message have you got?
Did you use the ownCloud manual?
Yes, I have this error:
<?xml version="1.0"?>
failure
997
Unauthorised
My request:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://admin:pass@myip/ocs/v1.php/cloud/apps/files');
xhr.onload = function() {
if (xhr.status !== 200) {
alert('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
changed to ssl but still problems:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://admin:pass@domain.com/index.php/apps/gallery/api/files/list');
xhr.onload = function() {
if (xhr.status !== 200) {
alert('Request failed. Returned status of ' + xhr.status);
}
};
xhr.send();
{"message":"CORS requires basic auth"}
You need to send a basic auth header with your username and password.
Withou ssl? can you give example?
username: admin
password: test
Please use google / your favorite search engine for such questions. This should show you how to use basic authentication within such requests.
The first error message was a configuration issue because of SSL.
The second message will be explained here: https://github.com/fcturner/passwords/wiki/ownCloud-Passwords-|-RESTful-API
Final solution:
Ext.Ajax.request({
url: 'https://domain/index.php/apps/gallery/api/files/list',
method: 'GET',
headers: {
Authorization: Ext.String.format('Basic {0}', btoa('admin:password'))
},
params: {
location: 'Photos',
mediatypes: 'image/png;image/jpeg;image/gif;image/x-xbitmap;image/bmp'
},
success: function() {
console.log(arguments)
},
failure: function() {
console.log(arguments)
}
});
Thank you so much