K
Kindeβ€’4mo ago
Adil Hemache

how to set provided_id when creating user via management API?

I tried the following with no luck:
# response = api.post(f"/user", json={
# "profile": {
# "given_name": user.first_name,
# "family_name": user.last_name,
# "provided_id": user.pk,
# },
# "organization_code": settings.KINDE_MANAGEMENT["ORGANIZATION_ID"],
# "identities": identities,
# })
# response = api.post(f"/user", json={
# "profile": {
# "given_name": user.first_name,
# "family_name": user.last_name,
# "provided_id": user.pk,
# },
# "organization_code": settings.KINDE_MANAGEMENT["ORGANIZATION_ID"],
# "identities": identities,
# })
8 Replies
onderay
onderayβ€’4mo ago
The provided_id field is not part of the profile object when creating a user. Instead, it should be included in the identities array. Here's the correct structure for creating a user with a provided_id: { "identities": [ { "details": { "email": "string", "phone": "string", "username": "string" }, "type": "email" } ], "organization_code": "string", "profile": { "family_name": "string", "given_name": "string" } } To set the provided_id, you should include it in the request body at the top level, not within the profile object. Here's how you might modify your Python code to correctly set the provided_id: response = api.post("/api/v1/user", json={ "profile": { "given_name": user.first_name, "family_name": user.last_name, }, "organization_code": settings.KINDE_MANAGEMENT["ORGANIZATION_ID"], "identities": identities, "provided_id": str(user.pk) # Add this line }) Note that the provided_id should be a string, so you may need to convert user.pk to a string if it's not already. Remember that the provided_id is described as "External id for user" in the API documentation , which aligns with your intention to use the primary key from your system.
Adil Hemache
Adil HemacheOPβ€’4mo ago
@Andre @ Kinde it didn't work πŸ˜• I can't retrieve provided_id nor see it in Kinde admin dashboard UI
python
r = api.post(f"/user", json={
# * must be a string
"provided_id": str(1000),
"profile": {
"given_name": "Test",
"family_name": "Test",
},
"organization_code": "org_d0ac253eda2",
"identities": [{
"type": "email",
"details": { "email": "[email protected]" },
}]
})
pprint(r.json())
r = api.get('/user', params={"id": r.json().get("id")})
print('#' * 100)
pprint(r.json())
python
r = api.post(f"/user", json={
# * must be a string
"provided_id": str(1000),
"profile": {
"given_name": "Test",
"family_name": "Test",
},
"organization_code": "org_d0ac253eda2",
"identities": [{
"type": "email",
"details": { "email": "[email protected]" },
}]
})
pprint(r.json())
r = api.get('/user', params={"id": r.json().get("id")})
print('#' * 100)
pprint(r.json())
log
{'created': True,
'id': 'kp_38c012726fe243f8b0e55aaa964d19a7',
'identities': [{'result': {'created': True, 'identity_id': 73},
'type': 'email'}]}
####################################################################################################
{'created_on': '2024-09-13T18:41:06.746997+00:00',
'failed_sign_ins': 0,
'first_name': 'Test',
'id': 'kp_38c012726fe243f8b0e55aaa964d19a7',
'is_suspended': False,
'last_name': 'Test',
'preferred_email': '[email protected]',
'total_sign_ins': 0}
{'created': True,
'id': 'kp_38c012726fe243f8b0e55aaa964d19a7',
'identities': [{'result': {'created': True, 'identity_id': 73},
'type': 'email'}]}
####################################################################################################
{'created_on': '2024-09-13T18:41:06.746997+00:00',
'failed_sign_ins': 0,
'first_name': 'Test',
'id': 'kp_38c012726fe243f8b0e55aaa964d19a7',
'is_suspended': False,
'last_name': 'Test',
'preferred_email': '[email protected]',
'total_sign_ins': 0}
to get provided_id I tried following requests: GET /api/v1/users GET /api/v1/user GET /users/kp_38c012726fe243f8b0e55aaa964d19a7/properties
Adil Hemache
Adil HemacheOPβ€’4mo ago
@Andre @ Kinde full script with config and everything, easier to debug πŸ™ ps: I made sure the M2M app has read/write to all user and user_properties scopes
onderay
onderayβ€’4mo ago
Sorry @Adil Hemache are you trying to get a property or the ID of an identity of a user? As if you want to get the provided_id, this is the call https://kinde.com/api/docs/#get-identity
Adil Hemache
Adil HemacheOPβ€’4mo ago
yes, but the documentation says that provided_id field is part of user response and not identity! assuming I want to use get identity endpoint, what's the ID of the identity ? πŸ€” as I only create one primary email identity in user creation request @Andre @ Kinde got all user identities, still, provided_id is not part of any GET /api/v1/users/{user_id}/identities
{'code': 'OK',
'has_more': False,
'identities': [{'created_on': '2024-09-14T18:15:52.950703+00:00',
'id': 'identity_0191f1bf9fad251c79f2c959be828fe8',
'is_confirmed': False,
'last_login_on': None,
'name': '[email protected]',
'total_logins': 0,
'type': 'email'}],
'message': 'Success'}
{'code': 'OK',
'has_more': False,
'identities': [{'created_on': '2024-09-14T18:15:52.950703+00:00',
'id': 'identity_0191f1bf9fad251c79f2c959be828fe8',
'is_confirmed': False,
'last_login_on': None,
'name': '[email protected]',
'total_logins': 0,
'type': 'email'}],
'message': 'Success'}
@Andre @ Kinde to reword our needs, we want to 1. set provided_id when creating the user using management API 2. able to get that provided_id later when listing users using management API note aside, the API documentations looks out dated and hard to follow
Daniel_Kinde
Daniel_Kindeβ€’4mo ago
Hi @Adil Hemache , I will check with our API team. The provided_id is really there to support the migration where your user data is coming from another source and being imported. Could you let me know this usecase you're trying to solve with the provided ID when you're creating via the API?
Adil Hemache
Adil HemacheOPβ€’4mo ago
@Daniel_Kinde so there is no way to set/get provided_id via the api?! should we just use custom property?
Oli - Kinde
Oli - Kindeβ€’4mo ago
Hey @Adil Hemache, I would suggest using a custom user property to store a custom ID against users for now, so you are not blocked. We are looking into this gap in the API where you cannot get/set provided_id for a user via the Kinde Management API. Let us know if you come across any issues using custom user properties for now.
Want results from more Discord servers?
Add your server