I am still trying to get play around with the API. However it’s my first time calling a REST Api.
All my POST queries are Unauthorized. While my GET query to /auth is successful.
What am I missing ?
Unfortunately the 401 is a bit of a catch all in the launcher source. Assuming that your body is encrypted and base 64’d, what does it look like in clear text?
Yeah, sorry, I am not sure what the issue is here just by looking. It might be an encryption problem. You can compare with other libraries to see how their requests work. You may have to debug the launcher yourself.
No problem
Isn’t it possible get an error code 400 somehow without valid body content ?
Or is a valid body content absolutely necesary to get something different from 401… ?
Empty body yields 500 …
Okay, thanks for pointing to the exact lines of code…
Since /auth is working fine i suppose my body is incorrect.
I’m not fit enough in .js to dig deeper into this at the moment.
yields: Error: 400: {"errorCode":-10,"description":"CoreError::OperationForbiddenForClient"}
On the second run. The error is at the getServiceDir call… Any ideas?
Also, please ignore the hack-job coding. Still learning nodejs. The syntax seems very foreign to me.
Is this possibly the cause for the error ? Can the launcher handle this properly ?
I can’t see how I could pass a string in C# to contain doubleQuotes without escaping them.
That is invalid JSON and could be the cause. In programming languages there is a difference between string literals (where you have to escape double quotes) and runtime strings (where they are not escaped). C# also allows you to prefix the string literal with @ that would obviate escaping. But that’s only for string literals. At this point I’d probably have to see the code. Whenever there is a bug, the best thing you could do is make the smallest possible test case to replicate.
As mentioned to the other poster, can you make the smallest possible test case to replicate from scratch instead of pasting your existing code? Also, set client.logger = console.log to see some HTTP debug details.
I want to create a new service, then get the info on that service… The code below is as condensed as I know how to make it:
let longName = 'wes';
let serviceName = 'www4';
p = p.then(_ => {
return safe.dns.addService(client, {longName: longName, serviceName: serviceName, serviceHomeDirPath: '/', isPathShared: true}).then(function(){
console.log('created new service')
})
})
p = p.then(_ => {
return safe.dns.getServiceDir(client, longName, serviceName).then(function(data){
console.log('dns data: ', data)
})
})
yields:
Calling GET http://localhost:8100/auth
RESP BODY OK
Calling PUT http://localhost:8100/dns
REQ BODY {"longName":"wes","serviceName":"www4","serviceHomeDirPath":"/","isPathShared":true}
RESP BODY OK
created new service
Calling GET http://localhost:8100/dns/www4/wes
RESP BODY {"errorCode":-10,"description":"CoreError::OperationForbiddenForClient"}
I have not tried creating a service tied to the root dir, I don’t think you can. The top level shared directory is “SAFEDrive” (as opposed to the top level non-shared directory of “MYAPP-Root-Dir”). Top level directories (i.e. /) are considered “private”. Private directories I don’t think can be tied to DNS. It might be better to get someone from maidsafe to confirm this.
Create a non-private sub directory and tie the service to that.
Edit: OK, I have thought about this. The DNS call you make is unauthorized and therefore cannot access a private directory. Before there was an issue where authing during an unauth’d operation actually failed. It might be fixed, I have to check. Then I have to check if I give the user in my API the option to perform that call while authorized if the private dir will be available.
it seems that the problem was indeed with creating in the root. Created a new dir, then set the service to use that dir instead of root with no other changes and it worked as expected.
Thanks for your help.
EDIT: Correction. Your second thought may also be true, if I create the dir as private, it fails the getServiceDir call, when private is false, it works.
// building json body
string json = “{‘dirPath’:‘/photos’,‘isPrivate’:true,‘metadata’:null,‘isVersioned’:false,‘isPathShared’:false}”;
// escaping doubleQuotes
json = json.Replace(“'”, @“”“”);
This is working fine for the /auth POST . The difference however between /auth and /nfs/directory is that in the second case, the body is encrypted.
While making a REST Api call with escaped doublequotes works fine in the first case, the escape characters are also encrypted in the second case. Decrypting within a non dotNet environment might cause the problem.
The single quote to double quote makes little sense, but it doesn’t appear to cause a wrong result. Nothing here is jumping out at me. Sorry. You’re gonna have to debug the launcher I’m afraid unless someone else pops in and sees the obvious issue. You can also compare it to the other clients that have been released and do not get 401’s.