plandex-ai/plandex · warning

Error unmarshalling request:

Error message

Error unmarshalling request: 

What it means

InviteUserHandler decodes the request body into shared.InviteRequest. When json.Decoder rejects the body, the handler responds 500 (note: arguably should be 400) with 'Error unmarshalling request: <err>'. It means the payload was not valid JSON or did not match InviteRequest's field types.

Source

Thrown at app/server/handlers/invites.go:60

	}

	if org.IsTrial {
		writeApiError(w, shared.ApiError{
			Type:   shared.ApiErrorTypeTrialActionNotAllowed,
			Status: http.StatusForbidden,
			Msg:    "Trial user can't invite other users",
		})

		return
	}

	currentUserId := auth.User.Id

	var req shared.InviteRequest
	err = json.NewDecoder(r.Body).Decode(&req)
	if err != nil {
		log.Printf("Error unmarshalling request: %v\n", err)
		http.Error(w, "Error unmarshalling request: "+err.Error(), http.StatusInternalServerError)
		return
	}
	req.Email = strings.ToLower(req.Email)

	// ensure current user can invite target user
	permission := shared.Permission(strings.Join([]string{string(shared.PermissionInviteUser), req.OrgRoleId}, "|"))

	if !auth.HasPermission(permission) {
		log.Printf("User does not have permission to invite user with role: %v\n", req.OrgRoleId)
		http.Error(w, "User does not have permission to invite user with role: "+req.OrgRoleId, http.StatusForbidden)
		return
	}

	// ensure user doesn't already have access to org via domain
	split := strings.Split(req.Email, "@")
	if len(split) != 2 {
		log.Printf("Invalid email: %v\n", req.Email)
		http.Error(w, "Invalid email: "+req.Email, http.StatusBadRequest)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Send a valid JSON body matching InviteRequest, e.g. {"email":"user@example.com","orgRoleId":"<role-id>","name":"..."} — validate with jq first
  2. Check the %v detail in the response; 'cannot unmarshal X into type string' names the mismatched field
  3. Set Content-Type: application/json and ensure the CLI/SDK version matches the server version
  4. If you control the server, consider changing this response to 400 Bad Request, since bad input is the usual cause

Example fix

// before
curl -X POST $URL -d 'email=foo@bar.com&role=admin'
// after
curl -X POST $URL -H 'Content-Type: application/json' -d '{"email":"foo@bar.com","orgRoleId":"admin"}'
Defensive patterns

Strategy: validation

Validate before calling

// Build and validate the InviteRequest body before sending
req := map[string]string{"email": email, "orgRoleId": roleID, "name": name}
if email == "" || roleID == "" {
    return errors.New("email and orgRoleId are required")
}
body, err := json.Marshal(req)
if err != nil {
    return fmt.Errorf("invalid invite payload: %w", err)
}

Try / catch

res, err := client.InviteUser(ctx, email, roleID)
if err != nil && strings.Contains(err.Error(), "Error unmarshalling request") {
    return fmt.Errorf("invite payload rejected — send JSON {email, orgRoleId} with correct types: %w", err)
}

Prevention

When it happens

Trigger: POST to the invite endpoint with an empty body, malformed JSON, email/orgRoleId/name as wrong JSON types (e.g. numbers instead of strings), or a body not matching the InviteRequest schema.

Common situations: Missing Content-Type combined with a form-encoded body; hand-written curl payloads with syntax errors; a CLI/SDK version whose InviteRequest JSON no longer matches the server's; a proxy mangling the body.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/9eeeab7f9f065537. Report an issue: GitHub.