New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Need help on using DirectAdmin API (Unauthorized Error)
Hello!
I am having a weird issue when using DA's API with basic auth (MXroute).
I'm 100% certain the credentials are correct, however I'm getting "Unauthorized" error on every even requests, while the API works fine on every odd requests.
I'll put a screenshot of my current code, as well as the error I'm getting when the "Unauthorized" error happens. If anyone experienced this issue, or knows a fix for it, any input will be highly appreciated.
Thanks!
Comments
Do you see the same behavior when you do the series of requests from Postman?
EDIT: Obligatory 4d chess galaxy brain comment, keep a counter and retry the request on even values
Yup, same happens with Postman as well.
Lol I was originally thinking of that to if no other options work. However, I think I found the issue.
It seems like when you send both the session cookie and the authentication credentials, DA will clear the session and log you out.
I was able to fix it by disabling cookie on requests.session.
line 10: 'applicatoin/json'
I haven't written anything against the DA API so I wouldn't know, but is there a particular reason you're using a session (instead of stateless requests) to interact with the API?
I was copy-pasting from some other code for testing. This wasn't the issue however, as DA doesn't seem to care the Accept header.
Session isn't required to interact with DA API. However, I couldn't think of a better way to send authentication data on every request without putting auth parameter on every function.