Okta api python sdk throwing json error

748 views Asked by At

I'm trying to create a user with the python sdk. When I run my script, I get the following error:

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/sitepackages/oktasdk-python/okta/framework/ApiClient.py", line 53, in post
if self.__check_response(resp, attempts):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/sitepackages/oktasdk-python/okta/framework/ApiClient.py", line 88, in  __check_response
raise OktaError(json.loads(resp.text))
okta.framework.OktaError.OktaError: The request body was not well-formed:  Could not read JSON

Here is a snippet of my code:

from okta.UsersClient import UsersClient
from collections import namedtuple

def main():

    create_okta_user()


def create_okta_user():

    usersClient = UsersClient("https://example.okta.com", "0d0d0dexamplekey")
    User = namedtuple("User", ["login", "email", "firstName", "lastName"], verbose=False, rename=False)
    user = User(login="[email protected]",
            email="[email protected]",
            firstName="user",
            lastName="tester")

    usersClient.create_user(user, activate=False)

    #usersClient.activate_user(user)

main()
1

There are 1 answers

1
kevlened On

It looks like you're trying to use a namedtuple, which is serialized to a json list, not an object.

Try using the User model like this:

from okta import UsersClient
from okta.models.user import User


def main():
    create_okta_user()

def create_okta_user():

    usersClient = UsersClient("https://example.okta.com", "0d0d0dexamplekey")

    user = User(login="[email protected]",
            email="[email protected]",
            firstName="user",
            lastName="tester")

    user = usersClient.create_user(user, activate=False)
    #usersClient.activate_user(user)

main()

http://developer.okta.com/docs/sdk/core/python_api_sdk/quickstart.html#create-a-user