How to allow Flask-Admin to accept JSON for record creation
<p>I would like to know if it is possible to use <code>Flask-Admin</code> with the python <code>requests</code> library to create new records in the database from a script. An example would be as such:</p>

<pre><code>import requests

new_userdata = {'username': 'testuser', 'confirmed_at': None, 'login_count': 0, 'last_login_at': None, 'active': False, 'password': 'password', 'current_login_ip': None, 'last_login_ip': None, 'current_login_at': None, 'email': 'test@test.com'}

url = "http://localhost:5000/admin/user/new/"

r = requests.post(url, data=new_userdata, headers={"content-type":"application/json")
</code></pre>

<p>I tried this already, and it <em>does</em> successfully create a new <code>user</code> record in the database, but all the fields in the record are <code>null</code>. Is there a configuration setting that needs to be changed to allow this sort of behavior? I wasn't able to find in the <code>Flask-Admin</code> documentation that discussed this kind of usage.</p>

<p>You're sending form data, but you're also saying that the content type is JSON.  If you were actually sending JSON data, you would either need to call <code>json.dumps</code>, or you would pass <code>json=</code> instead of <code>data=</code>.  Just remove the header and send form data, as it's obviously sufficient to handle the data you're sending and Flask-Admin recognizes it.</p>

python json flask python-requests flask-admin