# Updating Program Memberships for Existing Users

## Updating Program Memberships

To update an existing program membership, you can make a **`PATCH`** request to the [`/v2/program-memberships/:program_membership_id`](broken://pages/8eqT8axl5iyR7wIoJ1Gr#v2-program-memberships-program_membership_id) endpoint.

### Request Parameters

* `external_user_id` (optional): The external user ID you want to update the program membership with.
* `phone` (optional): The phone number to update the program membership with. Note: this should be formatted with area code first like +17891234567. If you send in an unformatted number we will format and set to US as long as there is an area code privided.
* `email` (optional): The user's email to set or update.
* `first_name` (optional): The user's first name.
* `last_name` (optional): The user's last name.
* `birthday` (optional): The user's birthday ("YYYY-MM-DD").
* `family_member_birthdays` (optional): An array of objects, each representing a family member. Each object can include the following fields:
  * `first_name` (required): The first name of the family member.
  * `last_name` (optional): The last name of the family member.
  * `birthday` (required): The birthday ("YYYY-MM-DD") of the family member.
  * `status` (required): The status of the family member ("active"/"inactive").

#### Example Request

```bash
curl -X PATCH 'https://loyalty.hang.xyz/partner-api/v2/program-memberships/membership_id_1' \
  -H 'X-API-Key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "external_user_id": "12345",
    "first_name": "joe",
    "last_name": "Smith",
    "birthday": "1989-02-25",
    "phone": "+17891234567",
    "email": "example@gmail.com",
    "family_member_birthdays": [
        {
          "first_name": "Anna", 
          "birthday": "2000-02-02", 
          "status": "active" 
        },
        {
          "first_name": "Mason",
          "last_name": "Smith",
          "birthday": "2002-01-01", 
          "status": "active" 
        }
    ]
  }'

```

### Response

If successful, the API will return a 200 OK status along with the details of the updated program membership.

#### Example Response

```json
{
  "membership": {
    "id": "membership_id_1",
    "external_user_id": "user123",
    "created_at": 1633887337,
    "phone": "+17891234567",
    "email": "example@gmail.com",
    "social_media_credentials": {
      "twitter_username": "updated_twitter",
      "instagram_username": "updated_instagram",
      "tiktok_username": "updated_tiktok"
    },
    "family_member_birthdays": [
      {
        "first_name": "Anna",
        "last_name": "",
        "birth_date": "2000-02-02",
        "status": "active"
      },
      {
        "first_name": "Mason",
        "last_name": "Smith",
        "birth_date": "2002-01-01",
        "status": "active"
      }
    ]
  }
}
```

### Implementing Program Membership Updates in Your Backend

After making the API call, Hang will update the selected program membership fields (  `external_user_id`, `phone` or a combination of them). Utilize the returned membership data to maintain accurate and up-to-date user information in your loyalty programs.

### Error Handling

If the API encounters an error, a relevant error message will be returned to guide you through the troubleshooting process. For example, if there is an issue with the `external_user_id` parameters, the API will return an error message describing the problem.


---

# 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://docs.hang.com/hang-platform/api-usage/updating-program-memberships-for-existing-users.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.
