Traccar create device giving Bad Request.

nithik2 years ago

Hello , Im trying to track the gps device in a google map fragment in android, every time i use the api to create a device or user it gives errors as bad request or 401 or 404 error.

Anton Tananaev2 years ago

Are you going to provide details?

nithik2 years ago

Hi anton this is my post request created with retrofit

    @POST("/users")
    @Headers("Content-Type: application/json")
    @FormUrlEncoded
    fun createuser(
        @Field("name") name: String?,
        @Field("email") email: String?,
        @Field("password") password: String?
    ): Call<TraccarUser?>?

but i'm getting errors with every request i make , i make the same api calls to other api they work just fine. tried logging in to already created users it works fine .
Tried creating a device though api with the admin account and again the same problem
I guess there is a catch with the post request , Is there something in missing ? i checked the android traccar app git too . Still no help.

Anton Tananaev2 years ago

This part doesn't make sense to me:

    @Headers("Content-Type: application/json")
    @FormUrlEncoded

Are you sending JSON or form?

nithik2 years ago

I'm sry i intend to send JSON to the api , can it also be done with a form by the way? or is sending JSON the correct way?

Anton Tananaev2 years ago

You can't use form. It has to be proper JSON. You can find some samples here:

https://github.com/traccar/traccar-manager-android/tree/native

nithik2 years ago

Understanding Your code or documentation is not possible
Please provide steps how can i create a user using the traccar API from android.

Anton Tananaev2 years ago

If you want someone to walk you through step by step, we provide paid support. Email support address to discuss details.