Traccar create device giving Bad Request.

nithika year 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 Tananaeva year ago

Are you going to provide details?

nithika year 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 Tananaeva year ago

This part doesn't make sense to me:

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

Are you sending JSON or form?

nithika year 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 Tananaeva year 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

nithika year 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 Tananaeva year ago

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