# Creating and Updating Attendees

In order to create and update attendees, the request needs to include a JSON array body that has at least one of the attendee objects. The objects can be of type:

* [UpsertByUser](/v2-en/services/attendee-management/creating-and-updating-attendees/upsert-by-user.md)
* [UpsertByEmail](/v2-en/services/attendee-management/creating-and-updating-attendees/upsert-by-email-guests.md)
* [UpdateByAttendanceCode](/v2-en/services/attendee-management/creating-and-updating-attendees/update-by-attendance-code.md)

{% hint style="info" %}
For all attendees in a session, an attendee's email, and user guid(*if applicable*) has to be unique.
{% endhint %}

**Example Request:**

{% hint style="warning" %}
Avoid making individual API calls in a loop since this endpoint accepts multiple attendee objects (both create and update operations) in a single request.
{% endhint %}

The request below shows the usage of all possible objects:

{% tabs %}
{% tab title="CURL" %}

```powershell
curl -L -X POST 'https://<DOMAIN>/api/groups/xapi/session/:SESSION_GUID/attendee/batch' \
--data-raw '
[
     // you can use a user_guid to insert or update, and it will parse all variables of that user to the attendee like email, mobile, and role(sending a role will override)
     // the response for this will show insert
    {
        "user_guid": "44EF7B95-81B0-419D-BB0D-DFBD545F6008"
    },
     // you can use a user_guid to insert or update, and it will parse all variables of that user to the attendee like email, mobile, and role(sending a role will override)
     // the response for this will show update
    {
        "user_guid": "7fd2b7ab-dfbe-4b35-a217-ec11791a4a80",
        "role": "a"
    },
     // a non existing user guid will get rejected
    {
        "user_guid": "7fd2b7ab-dfbe-4b35-a217-ec11791a4a8x"
    },
    // you can insert or update a user with email, name, surname and role(defaults to 'u' if not present)
    // this is the correct format to use when adding external attendees (meaning they are not registered as a user)
    // response will show insert
    {
        "email": "doe@example.com",
        "name": "John",
        "surname": "Doe",
        "role": "e"
    },
    // you can insert or update a user with email, name, surname and role(defaults to 'u' if not present)
    // response will show update
    {
        "email": "doe2@example.com",
        "name": "updated_name",
        "surname": "Doe",
        "role": "u"
    },
    // you can update an existing attendee with its attendance_code
    {
        "attendance_code": "5786FF4C-4A93-45A2-BAF1-9461F376E8C5",
        "role": "e"
    },
    // non existent attendance_code will get rejected
    {
        "attendance_code": "2BA64ED7-EE65-4164-A0A0-85A45E8D0BFx",
        "mobile": "+00 000 00 00"
    }
]
'
```

{% endtab %}

{% tab title="Python" %}

```python
client.attendees.upsert_attendees(
        "7E040E2D-D1EC-4853-A3FB-8C69FE9BDD1F",
        [
            {
                "user_guid": "44EF7B95-81B0-419D-BB0D-DFBD545F6008"
            },
            {
                "user_guid": "7fd2b7ab-dfbe-4b35-a217-ec11791a4a80",
                "role": "a"
            },
            {
                "user_guid": "7fd2b7ab-dfbe-4b35-a217-ec11791a4a8x"
            },
            {
                "email": "doe@example.com",
                "name": "John",
                "surname": "Doe",
                "role": "e"
            },
            {
                "email": "doe2@example.com",
                "name": "updated_name",
                "surname": "Doe",
                "role": "u"
            },
            {
                "attendance_code": "5786FF4C-4A93-45A2-BAF1-9461F376E8C5",
                "role": "e"
            },
            {
                "attendance_code": "2BA64ED7-EE65-4164-A0A0-85A45E8D0BFx",
                "mobile": "+00 000 00 00"
            }
        ]
    );
```

{% endtab %}
{% endtabs %}

Example Response:

The response for this operation includes a json object like so:

```json
{
    "approved": [
        // JSON objects for attendee
    ],
    "rejected": [
        // JSON objects for attendee
    ]
}
```

{% hint style="info" %}
Response Status Codes will vary depending on how the operations went:

* <mark style="color:green;">**200 OK**</mark><mark style="color:green;">:</mark> All operations completed successfully
* <mark style="color:green;">**207 Multi-Status**</mark><mark style="color:green;">:</mark> Partial success - some operations failed
* <mark style="color:red;">**400 Bad Request**</mark><mark style="color:red;">:</mark> All operations failed
  {% endhint %}

```json
{
    "approved": [
        {
            "session_id": "70826",
            "user_id": "",
            "user_guid": "",
            "attendee_id": "503735",
            "attendance_code": "5786FF4C-4A93-45A2-BAF1-9461F376E8C5",
            "name": "non-existent",
            "surname": "non-existent",
            "email": "non-existent@example.com",
            "role": "e",
            "mobile": null,
            "creation_date": "2024-10-18T21:39:21.575387+03:00",
            "updating_date": "2024-10-18T21:39:39.070343+03:00",
            "operation": "updated"
        },
        {
            "session_id": "70826",
            "user_id": "8208",
            "user_guid": "44EF7B95-81B0-419D-BB0D-DFBD545F6008",
            "attendee_id": "503736",
            "attendance_code": "F344309A-BA6C-4D92-9C5A-4F2EE65AFB34",
            "name": "logar",
            "surname": "komutan",
            "email": "44EF7B95-81B0-419D-BB0D-DFBD545F6008@example.com",
            "role": "a",
            "mobile": "",
            "creation_date": "2024-10-18T21:39:39.125758+03:00",
            "updating_date": "2024-10-18T21:39:39.125758+03:00",
            "operation": "inserted"
        },
        {
            "session_id": "70826",
            "user_id": "4490",
            "user_guid": "7fd2b7ab-dfbe-4b35-a217-ec11791a4a80",
            "attendee_id": "503725",
            "attendance_code": "D1CCAE51-7B5B-4885-A10B-8B30DFA5F014",
            "name": "Atakan",
            "surname": "Bodur",
            "email": "atakan@example.com",
            "role": "a",
            "mobile": "+905314237888",
            "creation_date": "2024-10-18T21:31:19.692427+03:00",
            "updating_date": "2024-10-18T21:39:39.125758+03:00",
            "operation": "updated"
        },
        {
            "session_id": "70826",
            "user_id": "0",
            "user_guid": null,
            "attendee_id": "503738",
            "attendance_code": "27A9E30B-48C3-4933-9E15-6752D686AB51",
            "name": "John",
            "surname": "Doe",
            "email": "doe@example.com",
            "role": "e",
            "mobile": null,
            "creation_date": null,
            "updating_date": null,
            "operation": "inserted"
        },
        {
            "session_id": "70826",
            "user_id": "0",
            "user_guid": null,
            "attendee_id": "503726",
            "attendance_code": "C937F71E-DE23-463E-A3CE-3DCB3F36830D",
            "name": "updated_name",
            "surname": "Doe",
            "email": "doe2@example.com",
            "role": "u",
            "mobile": null,
            "creation_date": null,
            "updating_date": null,
            "operation": "updated"
        }
    ],
    "rejected": [
        {
            "model": {
                "session_id": "70826",
                "user_id": "",
                "user_guid": "",
                "attendee_id": "-1",
                "attendance_code": "",
                "name": null,
                "surname": null,
                "email": null,
                "role": null,
                "mobile": "+00 000 00 00",
                "creation_date": null,
                "updating_date": null,
                "operation": "error"
            },
            "state": {
                "code": 12,
                "details": "Attendee not found"
            }
        },
        {
            "model": {
                "session_id": "-1",
                "user_id": "",
                "user_guid": "7fd2b7ab-dfbe-4b35-a217-ec11791a4a8x",
                "attendee_id": "-1",
                "attendance_code": "",
                "name": null,
                "surname": null,
                "email": null,
                "role": null,
                "mobile": null,
                "creation_date": null,
                "updating_date": null,
                "operation": "error"
            },
            "state": {
                "code": 12,
                "details": "Attendee not found"
            }
        }
    ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.perculus.com/v2-en/services/attendee-management/creating-and-updating-attendees.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
