Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Need help on using DirectAdmin API (Unauthorized Error)
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.

Need help on using DirectAdmin API (Unauthorized Error)

sanvitsanvit Member

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

  • jmgcaguiclajmgcaguicla Member
    edited May 2022

    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

    image

    Thanked by 1sanvit
  • sanvitsanvit Member

    @jmgcaguicla said:
    Do you see the same behavior when you do the series of requests from Postman?

    Yup, same happens with Postman as well.

    EDIT: Obligatory 4d chess galaxy brain comment, keep a counter and retry the request on even values

    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'

  • jmgcaguiclajmgcaguicla Member
    edited May 2022

    @sanvit said:
    I was able to fix it by disabling cookie on requests.session.

    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?

  • sanvitsanvit Member

    @budi1413 said:
    line 10: 'applicatoin/json'

    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.

    @jmgcaguicla said: but is there a particular reason you're using a session (instead of stateless requests) to interact with the API?

    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.

    Thanked by 1jmgcaguicla
Sign In or Register to comment.