Traccar API - Password Reset

Hi,
is there any option to send a pasword reset email from API or by http parameters POST or GET?
Thank you!

Anton Tananaev3 years ago

Yes. Check what API official web app is using and do the same thing.

Thank you, I've found this:

response = await fetch('/api/password/reset', {
        method: 'POST',
        body: new URLSearchParams(`email=${encodeURIComponent(email)}`),
Anton Tananaev3 years ago

You can also just look at network requests using your browser network tool, which is much easier than searching the code.

Can somebody help me with this code in dart/flutter for password reset?

static Future<http.Response> passwordReset(String email) async {
       headers['content-type'] = "application/json; charset=utf-8";
       headers['Accept'] = "application/json";
       String request = json.encode("email=" + Uri.encodeQueryComponent(email));
       final response = await http.post(
              Uri.parse("https://mytraccarserver.com/api/password/reset"),
              body: request,
             headers: headers
           );
       return response;
  }

Now the response is "Unsupported Media Type"

Anton Tananaev3 years ago

Content type is obviously wrong. Have you checked what official web app sends as I recommended? Please provide it here.

Ok solved, thank you.
The correct lines are:

headers['content-type'] = "application/x-www-form-urlencoded; charset=UTF-8";
String request = "email=" + Uri.encodeQueryComponent(email);
Rishi12 days ago

Hi Anton,

Is there an API available for the forgot password feature? While using the user edit API (/api/users/{user_id}) with the PUT method, we also need to pass the JSESSION ID, which requires the user to authenticate.

Is there any alternative or scope for implementing the forgot password feature without requiring prior authentication? other than directly editing the DB

Anton Tananaev12 days ago

Yes, there is. Check what the official app is doing.

Rishi12 days ago

Screenshot 2024-12-13 200727.png

I could find any forgot password option in the web app, could you please correct if I am referring the wrong item ?

Thank you

Anton Tananaev12 days ago

Have you enabled email in the config?

Rishi11 days ago

No, I believe. Email in the config means this one
ldap.mailAttribute

Anton Tananaev11 days ago

No, email means SMTP configuration.

Rishi11 days ago

No, we didn't set any smtp configurations.
Are you referring this attribute : mail.smtp.systemOnly (This is not present in our config file). Could you please let me know what value we have to enter here. ?

Anton Tananaev11 days ago