How to create a user with credentials in okta using python sdk
Is there a way to create an okta user with credentials using python
Creates a user with no recovery questions and answers. The new user will be able to log in immediately upon activation using the assigned password. This flow is a common occurrence when developing custom user registration.
curl -v -X POST \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: SSWS ${api_token}" \
-d '{
"profile": {
"firstName": "Isaac",
"lastName": "Brock",
"email": "isaac.brock@example.com",
"login": "isaac.brock@example.com",
"mobilePhone": "555-415-1337"
},
"credentials": {
"password" : { "value": "tlpWENT2m" }
}
}' "https://${org}.okta.com/api/v1/users?activate=false"
This using Curl
+3
source to share
1 answer
Using library requests in Python:
import requests
url = '{{org}}.okta.com/api/v1/users'
headers = {
'accept': 'application/json',
'authorization' : 'SSWS {{api_token}}',
'content-type': 'application/json'
}
body = {
'profile': {
'firstName': 'Isaac',
'lastName': 'Brock',
'email': 'isaac@{{email_suffix}}',
'login': 'isaac@{{email_suffix}}'
},
'credentials': {
'password' : { 'value': '{{password}}' }
}
}
r = requests.post(url, headers=headers, json=body)
# r.json
Using the Okta Python SDK , you need to create client
and then call the method first create_user()
.
from okta import UsersClient
from okta.models.user import User
usersClient = UsersClient("https://{{org}}.okta.com", "{{api_token}}")
user = User(login='isaac@{{email_suffix}}',
email='isaac@{{email_suffix}}',
firstName='Isacc',
lastName='Brock')
user = usersClient.create_user(user, activate=False)
+3
source to share