Update a user (API) error

Method PUT /api/v4/users/{user_id} always gives an error “Invalid or missing user in request body. Although I pass existing user id in URL and in BODY data (“id”=”{user_id}"). Other methods work, including GET /api/v4/users/{user_id}

Can you please paste the full curl request here for clarity? Also, what is the Mattermost server version you are using?

Mattermost 6.0

I’m use PHP:

        $data = array(
            "id" => $userId,
            "create_at" => "01-01-2020",
            "username" => $username,
            "first_name" => $firstName,
            "last_name" => $lastName,
            "nickname" => $nickname,
            "locale" => $locale,
            "position" => $position,
            "props" => $props,
            "notify_props" => $notifyProps,

        $url = $this->domain.'/api/v4/users/'.$userId;
	$headers = [];
        $headers[] = 'Authorization: Bearer '.$token;
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

        $result = curl_exec($ch);

The “create_at” field is an int64 field containing an epoch timestamp. Not a string.

It’s not directly mentioned in the request type, but you can see the response type here: Mattermost API Reference

1 Like