# User creation API: ‘active’ attribute set to True but returns False in response

**URL:** <https://meta.discourse.org/t/user-creation-api-active-attribute-set-to-true-but-returns-false-in-response/344908>\
**Category:** Product Support\
**Tags:** rest-api\
**Created:** [December 30, 2024, 4:39pm UTC](https://meta.discourse.org/t/user-creation-api-active-attribute-set-to-true-but-returns-false-in-response/344908 "2024-12-30T16:39:14Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![luigi7up](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/luigi7up/32/477213_2.png) [@luigi7up](https://meta.discourse.org/u/luigi7up)\
**Post date:** [December 30, 2024, 4:39pm UTC](https://meta.discourse.org/t/user-creation-api-active-attribute-set-to-true-but-returns-false-in-response/344908/1 "2024-12-30T16:39:14Z")

</div>

Hi all,

I’m using Python to create users via the Discourse API. The user creation request is returning a success response, but I’m encountering an issue where the active attribute in the response is always false, even though I explicitly set it to true in the payload. The confirmed attribute is set to true, and that works fine.

Here’s the code:

```python
import csv
import requests
import json
from datetime import datetime

# Discourse API details
discourse_url = "https://forum.hobiguru.com/" # Replace with your Discourse URL
api_key = "your-api-key" # Replace with your Discourse API Key
api_username = "system" # Admin username

# Request headers
headers = {
    "Api-Key": api_key,
    "Api-Username": api_username,
    "Content-Type": "application/json"
}

# Function to create a user
def create_user(username, name, email, password, bio, location, confirmed, active, join_date):
    url = f"{discourse_url}/users.json"
    join_date_str = join_date.strftime('%Y-%m-%dT%H:%M:%SZ')

    payload = {
        "name": name,
        "email": email,
        "password": password,
        "username": username,
        "active": True, # Set active to True by default
        "confirmed": True, # Set confirmed to True by default
        "created_at": join_date_str
    }

    print(f"\nRequest URL: {url}")
    print(f"Request Headers: {json.dumps(headers, indent=2)}")
    print(f"Request Payload: {json.dumps(payload, indent=2)}")

    response = requests.post(url, json=payload, headers=headers)
    
    if response.status_code == 200:
        response_json = response.json()
        if response_json.get("success"):
            print(f"User creation successful: {json.dumps(response_json, indent=2)}")
        else:
            print(f"User creation failed. Reason: {response_json.get('message')}")
            print(f"Errors: {json.dumps(response_json.get('errors'), indent=2)}")
    else:
        print(f"Request failed: {response.status_code}, {response.text}")

# Reading users from a CSV file
with open('input_users.csv', mode='r', encoding='utf-8') as file:
    reader = csv.DictReader(file)
    for row in reader:
        # Extract user details from the row
        create_user(row['Username'], row['Name'], row['Email'], row['Password'], row['Bio'], row['Location'], row['Confirmed'] == 'TRUE', row['Active'] == 'TRUE', datetime.strptime(row['Join Date'], '%Y-%m-%dT%H:%M:%SZ'))

```

I get this printed:

```terminal
 Request to create a user

{'name': 'Goran', 'email': 'bla+blaaa@gmail.com', 'password': 'P@ssword!23', 'username': 'goran12', 'active': True, 'confirmed': True, 'created_at': '2024-11-04T10:20:34Z'}
Request URL: https://forum.hobiguru.com/users.json
Request Headers:
{
  "Api-Key": "d9---------------e564d65d9b5a3",
  "Api-Username": "system",
  "Content-Type": "application/json"
}
Request Payload:
{
  "name": "Goran",
  "email": "'bla+blaaa@gmail.com",
  "password": "P@ssword!23",
  "username": "goran12",
  "active": true,
  "confirmed": true,
  "created_at": "2024-11-04T10:20:34Z"
}
Response:

Full Response: {
  "success": true,
  "active": false,
  "message": "Va\u0161 ra\u010dun je aktiviran i spreman za kori\u0161tenje."
}
Request was successful and user got created:
{'success': True, 'active': False, 'message': 'Vaš račun je aktiviran i spreman za korištenje.'}

```

**Problem:**

• Despite passing “active”: True in the payload, the active attribute in the response is always false and when I look for the users in the discourse admin panel I cannot find any

• The API returns success: true, but the user does not seem to be fully activated.

**Questions:**

1. Is there something I might be missing in my request that could cause the active attribute to not be set correctly?

2. Are there any specific conditions in Discourse’s API that would override the active attribute, even if it’s explicitly set to true?

Any insights or advice would be greatly appreciated!

---

_[View the full topic](https://meta.discourse.org/t/user-creation-api-active-attribute-set-to-true-but-returns-false-in-response/344908)._
