Query rest api whether a user already exists

Hi Everybody, I would appreciate any help.

Infos:

  • Used Zammad version: 3.2.x
  • Used Zammad installation source: package Zammad DEB Repo
  • Operating system: Ubuntu 18.04
  • Browser + version: Chrome Version 80.0.3987.122

Expected behavior:

query rest api and search for email or lastname to know, if a user already exists

Actual behavior:

GET https://…/api/v1/users/
will list all users. That’s working.

I want to search for a user with a specific email or lastname. It won’t work.
I get Status 200 ok but the Response is empty

Steps to reproduce the behavior:

GET https://…/api/v1/users/
Response:
{
“id”: 234,
“organization_id”: null,
“login”: “test3@test.de”,
“firstname”: “Else3”,
“lastname”: “Test2”,
“email”: “test3@test.de”,

}

With the following Requests the response is [] and Status 200 ok.

GET /api/v1/users/search?query=test2&expand=true’
GET /api/v1/users/search?query=test3@test.de&expand=true’
GET /api/v1/users/search?query=lastname:test2
GET /api/v1/users/search?query=email:test3@test.de

Thanks for any hints and suggestions.

Bye Sabrina

You’ll need to properply encode your requests when you’re talking via get parameters. Otherwise whatever tool you use will give you a hard time.

/api/v1/search?query=email%3Aalias%40domain.tld

Zammad will return HTTP/200 at any situation in the current situation. This is -at this moment- correct behavior. (Even if it feels wrong)

The difference if your payload you’ll get:

This happens if we find the user:

{
    "assets": {
        "User": {
            "3": {
                "id": 3,
                "organization_id": 2,

                [...]

                "role_ids": [
                    1,
                    2
                ],
                "organization_ids": [],
                "authorization_ids": [],
                "group_ids": {
                    "1": [
                        "full"
                    ]
                },
                "accounts": {}
            },
            "1": {
                "id": 1,
                "organization_id": null,
                "login": "-",
                "firstname": "-",
                "lastname": "",
                "email": "",
                "image": null,
                "image_source": null,
                "web": "",
                "phone": "",
                "fax": "",
                "mobile": "",
                "department": "",
                "street": "",
                "zip": "",
                "city": "",
                "country": "",
                "address": "",
                "vip": false,
                "verified": false,
                "active": false,
                "note": "",
                "last_login": null,
                "source": null,
                "login_failed": 0,
                "out_of_office": false,
                "out_of_office_start_at": null,
                "out_of_office_end_at": null,
                "out_of_office_replacement_id": null,
                "preferences": {},
                "updated_by_id": 1,
                "created_by_id": 1,
                "created_at": "2020-02-14T03:51:47.115Z",
                "updated_at": "2020-02-14T03:51:47.115Z",
                "role_ids": [],
                "organization_ids": [],
                "authorization_ids": [],
                "group_ids": {},
                "accounts": {}
            }
        },
        "Role": {
            "1": {
                "id": 1,
                "name": "Admin",
                "preferences": {
                    "not": [
                        "Customer"
                    ]
                },
                "default_at_signup": false,
                "active": true,
                "note": "To configure your system.",
                "updated_by_id": 1,
                "created_by_id": 1,
                "created_at": "2020-02-14T03:51:47.244Z",
                "updated_at": "2020-02-14T03:51:47.244Z",
                "permission_ids": [
                    1,
                    36,
                    56,
                    46
                ],
                "group_ids": {}
            },
            "2": {
                "id": 2,
                "name": "Agent",
                "preferences": {
                    "not": [
                        "Customer"
                    ]
                },
                "default_at_signup": false,
                "active": true,
                "note": "To work on Tickets.",
                "updated_by_id": 1,
                "created_by_id": 1,
                "created_at": "2020-02-14T03:51:47.248Z",
                "updated_at": "2020-02-14T03:51:47.248Z",
                "permission_ids": [
                    36,
                    48,
                    51,
                    53,
                    57
                ],
                "group_ids": {}
            }
        },
        "Group": {
            "1": {
                "id": 1,
                "signature_id": 1,
                "email_address_id": 1,
                "name": "Sales",
                "assignment_timeout": null,
                "follow_up_possible": "yes",
                "follow_up_assignment": true,
                "active": true,
                "note": "Standard Group/Pool for Tickets.",
                "updated_by_id": 1,
                "created_by_id": 1,
                "created_at": "2020-02-14T03:51:47.597Z",
                "updated_at": "2020-02-27T09:47:35.018Z",
                "user_ids": [
                    3,
                    6,
                    4,
                    5
                ]
            }
        },
        "Organization": {
            "2": {
                "id": 2,
                "name": "Zammad GmbH",
                "shared": true,
                "domain": "",
                "domain_assignment": false,
                "active": true,
                "note": "",
                "updated_by_id": 1,
                "created_by_id": 1,
                "created_at": "2020-02-14T07:44:09.071Z",
                "updated_at": "2020-02-17T08:11:02.080Z",
                "member_ids": [
                    3
                ]
            }
        }
    },
    "result": [
        {
            "id": 3,
            "type": "User"
        }
    ]
}

And this if we don’t:

{
    "assets": {},
    "result": []
}

So basically you may want to check if “result” is empty. If so, you didn’t find anything.

Hi, thank you very much for answering. I am glad, this works for me. :smiley: :

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.