peini7
peini74mo ago

V2 Users API not working

Iam trying to use the V2 Users API as shown here: https://zitadel.com/docs/apis/resources/user_service_v2/user-service-create-user But i always get "Method not allowed" What am i doing wrong?
ZITADEL Docs
Create a new human or machine user in the specified organization.
24 Replies
Jim Morrison
Jim Morrison3mo ago
Hey there @peini7 do you have a code snipit that we can reference. Would love to work more with @Rajat on what could be happening here. Thanks!
peini7
peini7OP3mo ago
I just used the default sample from the docs:
POST: http://localhost:8000/v2/users/new

{
"organizationId": "323336545845182467",
"userId": "163840776835432345",
"username": "minnie-mouse",
"human": {
"profile": {
"givenName": "Minnie",
"familyName": "Mouse",
"nickName": "Mini",
"displayName": "Minnie Mouse",
"preferredLanguage": "en",
"gender": "GENDER_FEMALE"
},
"email": {
"email": "mini@mouse.com"
},
"password": {
"password": "Secr3tP4ssw0rd!",
"changeRequired": false
}
}
}
POST: http://localhost:8000/v2/users/new

{
"organizationId": "323336545845182467",
"userId": "163840776835432345",
"username": "minnie-mouse",
"human": {
"profile": {
"givenName": "Minnie",
"familyName": "Mouse",
"nickName": "Mini",
"displayName": "Minnie Mouse",
"preferredLanguage": "en",
"gender": "GENDER_FEMALE"
},
"email": {
"email": "mini@mouse.com"
},
"password": {
"password": "Secr3tP4ssw0rd!",
"changeRequired": false
}
}
}
` I also thought that i maybe need to enable "Use V2 Api in Console for User creation" under the feature flags but this doesn't make a difference Port is correct, I'am running it on 8000 btw Authentication is a Personal Access token sent as a Bearer token
Biscottex
Biscottex3mo ago
I am getting the same error. I am using a private key (JWT) and I fetch a fresh token with it. The search of users is working fine but the creation of new user is giving me a Method Not allowed error.
peini7
peini7OP3mo ago
Yes i can confirm, search is working
Rajat
Rajat3mo ago
hey @Biscottex pls try it witthout the new
POST: http://localhost:8000/v2/users

{
"organizationId": "323336545845182467",
"userId": "163840776835432345",
"username": "minnie-mouse",
"human": {
"profile": {
"givenName": "Minnie",
"familyName": "Mouse",
"nickName": "Mini",
"displayName": "Minnie Mouse",
"preferredLanguage": "en",
"gender": "GENDER_FEMALE"
},
"email": {
"email": "mini@mouse.com"
},
"password": {
"password": "Secr3tP4ssw0rd!",
"changeRequired": false
}
}
}
POST: http://localhost:8000/v2/users

{
"organizationId": "323336545845182467",
"userId": "163840776835432345",
"username": "minnie-mouse",
"human": {
"profile": {
"givenName": "Minnie",
"familyName": "Mouse",
"nickName": "Mini",
"displayName": "Minnie Mouse",
"preferredLanguage": "en",
"gender": "GENDER_FEMALE"
},
"email": {
"email": "mini@mouse.com"
},
"password": {
"password": "Secr3tP4ssw0rd!",
"changeRequired": false
}
}
}
it should work 🙂
Biscottex
Biscottex3mo ago
Without the new it is the search functionality. https://zitadel.com/docs/apis/resources/user_service_v2/user-service-list-users To be sure, I tested, I got a result but I do not have any new user. I have 2 organization and I tried on both. I am running Zitadel 3.2.2).
ZITADEL Docs
Search for users. By default, we will return all users of your instance that you have permission to read. Make sure to include a limit and sorting for pagination.
Biscottex
Biscottex3mo ago
Here is part of my Rust code. Maybe the scope is wrong. pub async fn fetch_oauth_token(signed_jwt: &String) -> Result<String, ErrorMsg> { let uri = OIDC_SERVER_URL.to_string() + "/oauth/v2/token"; let scope = String::from("openid profile urn:zitadel:iam:org:project🆔zitadel:aud urn:zitadel:iam:org🆔243491102324228105 urn:zitadel:iam:org:roles🆔243491102324228105"); let data = OauthSignedTokenBody { grant_type: String::from("urn:ietf:params:oauth:grant-type:jwt-bearer"), scope, assertion: signed_jwt.to_string() }; let request = Request::builder() .method("POST") .uri(uri) .header("Content-Type", "application/x-www-form-urlencoded") .version(Version::HTTP_2) .body(Body::from(serde_urlencoded::to_string(&data)?))?; ... pub async fn create_zit_user(body_type_query: &ZitBodyCreateNewUser) -> Result<String, ErrorMsg> { let oidc_server_url = OIDC_SERVER_URL.to_string(); let signed_jwt = create_signed_jwt_from_private_key(&oidc_server_url).await?; let access_token = fetch_oauth_token(&signed_jwt).await?; let uri = oidc_server_url + "/v2/users/new"; let mut bearer_token = "Bearer ".to_owned(); bearer_token.push_str(&access_token); println!("bearer_token = {}", bearer_token); let request = Request::builder() .method("POST") .uri(uri) .header("Accept", "application/json") .header("Content-Type", "application/json") .header("Authorization", bearer_token) .version(Version::HTTP_2) .body(Body::from(serde_json::to_vec(&body_type_query)?)) ?; let prod = crate::entity::PROD.to_string(); let response = if String::from("true").eq(&prod) { super::get_hyper_client()?.ready().await?.call(request).await? } else { super::get_hyper_client_unsecure().await?.ready().await?.call(request).await? };
Rajat
Rajat3mo ago
hi @Biscottex thanks for clarifying that the breaking vhanges exist on rust as I was using postman curl, let me check and I will get back to you.
peini7
peini7OP3mo ago
I will do some more tests tomorrow but i can confirm that without the /new, its the search. First i thought it was working because it returned a user but then i realized that it was just the search result 😂
Biscottex
Biscottex3mo ago
I have the same issue with CURL. (I tested it as well with Zitadel v3.3.0) curl -L -k 'https://localhost:8686/v2/users/new' \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer 0-gOTLp8OQsHVZw8_SnxpOrtYYeJR_3Kqeg-jVQI_oKSF_XJSVgwgSzgTG1rEPXiS30ln-p3776hh54yYOTz2WbaX3KuMbTZxAtFaeef' \ --data-raw '{ "organizationId": "322608463559589897", "userId": "163840776835432345", "username": "minnie-mouse", "human": { "profile": { "givenName": "Minnie", "familyName": "Mouse", "nickName": "Mini", "displayName": "Minnie Mouse", "preferredLanguage": "en", "gender": "GENDER_FEMALE" }, "email": { "email": "mini@mouse.com" }, "password": { "password": "Secr3tP4ssw0rd!", "changeRequired": false } } }' {"code":12,"message":"Method Not Allowed"}
Manuel
Manuel3mo ago
same thing here: curl --request POST \ --url https://zitadel.example.com/v2/users/new \ --header 'Authorization: Bearer xxx’ \ --header 'Content-Type: application/json' \ --data '{ "organizationId": “xxx”, "username": "test", "machine": { "name": "test-machine-user" } }’ calling the deprecated https://zitadel.example.com/v2/users/human endpoint with the same token works
beohoang98
beohoang983mo ago
Same issue happens to me, I used service account tokens with Org Admin role, and using Zitadel Cloud, not self-hosted. POST /v2/users/human --> works, created new user ✅ POST /v2/users/ --> works, search users successfully ✅ POST /v2/users/new --> 405 Method not allowed ❌
lev
lev3mo ago
Good qustion, I second it. Probably my V2 issue can be fixed by moving to V1?
Rajat
Rajat3mo ago
hi @beohoang98 @Manuel @lev thanks for reporting that is broken /v2/users/new I indeed checked it and it is broken. Can anyone please open an issue for the same?. Thanks
lev
lev3mo ago
I think there is an issue already
lev
lev3mo ago
GitHub
[Bug]: Method not allow for V2 user update · Issue #10083 · zitad...
Preflight Checklist I could not find a solution in the documentation, the existing issues or discussions I have joined the ZITADEL chat Environment Self-hosted Version 3.3.0 Database PostgreSQL Dat...
Rajat
Rajat3mo ago
hi @lev thanks, nobidy tagged me or made me aware about it.I see it was akready moved into PM, so it should be resolved
lev
lev3mo ago
I worked my case around by checking the sdk code and finding the working url , not the one described in docs . Now I faced another issue 🙂
Rajat
Rajat3mo ago
hey @lev feel free to open a PR, we really appreiciate it comijng from a community memeber, you can update the issue with your findings and I can guide you what could be missing
lev
lev3mo ago
Sure , will do later today . Would you mind if I tag you here after I create it ?
Rajat
Rajat3mo ago
suure
lev
lev3mo ago
GitHub
[Bug]: Method not allow for V2 user update · Issue #10083 · zitad...
Preflight Checklist I could not find a solution in the documentation, the existing issues or discussions I have joined the ZITADEL chat Environment Self-hosted Version 3.3.0 Database PostgreSQL Dat...
Rajat
Rajat3mo ago
hi @lev and thanks, I will check it with my team and get it in touch with the engineers.
lev
lev3mo ago
it looks like that the real v2 user update is some mix between what is written in docs about v1 and v2

Did you find this page helpful?