API not recieving email and password for authentication

1. What is the problem? Be very detailed.
I try to authenticate via the API using code like this:

import requests

values = {
    "email": "my.email.address@example.com",
    "password": "my.super.secure.password"
  }


headers = {
  'Content-Type': 'application/json'
}
response_body = requests.post('https://odk.example.com/v1/sessions', data=values)

print (response_body.text)

The response is always

{"message":"Required parameters missing. Expected (email, password), got (email: undefined, password: undefined).","code":400.3,"details":{"expected":["email","password"],"got":{}}}

2. What app or server are you using and on what device and operating system? Include version numbers.

ODK Central v1.1.2 on both Google Cloud and Digital Ocean

3. What you have you tried to fix the problem?

Disabled firewall. No effect.

4. What steps can we take to reproduce the problem?

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.

Have a look at the Python example provided by @yanokwa.
You must provide your request content in JSON format.

import json
response_body = requests.post('https://odk.example.com/v1/sessions',
                              data=json.dumps(values),
                              headers=headers)
3 Likes

Was indeed the solution. Thanks. The example is illustrative.

1 Like