PUT/PATCH Method

PUT/PATCH Methods play a vital role in managing contacts. Using this HTTP method you can update existing contacts.

Updating a Contact

To update details of contact the id_or_email is required argument. So you need to append the id_or_email to your PUT/PATCH request. The following example updates contact we just created.

You can also perform this operation by setting “id_or_email” to user id of a user and passing by_user_id = true. This will update contact related to the user id.

http://yoursite.com/wp-json/gh/v2/contact

Much like creating contacts, you can pass the contact array with the updated contact details.

{
    "id_or_email":"email@example.com",
    "contact": {
        "email": "update_email@example.com",
        "first_name": "Jane",
        "last_name": "Doe",
        "user_id": "1",
        "owner_id": "1",
        "optin_status": "1",
        "meta": {
            "primary_phone": "1234567890",
            "primary_phone_extension": "5555",
            "street_address_1": "25 Lesmill Rd",
            "street_address_2": "Unit D",
            "city": "North York",
            "postal_zip": "M3B 2T3",
            "region": "Ontario",
            "country": "CA",
            "notes": "",
            "lead_source": "",
            "source_page": "",
            "custom_meta": "updated meta"
        }
    }
}

If everything goes according to plan you will receive the following response.

{
    "contact": {
        "data": {
            "email": "update_email@example.com",
            "first_name": "Jane",
            "last_name": "Doe",
            "user_id": "1",
            "owner_id": "1",
            "optin_status": "1",
            "date_created": "2019-08-02 08:28:32",
            "ID": "1025",
            "gravatar": "https:\/\/secure.gravatar.com\/avatar\/5658ffccee7f0ebfda2b226238b1eb6e?s=300&d=mm&r=g"
        },
        "meta": {
            "primary_phone": "1234567890",
            "primary_phone_extension": "5555",
            "street_address_1": "25 Lesmill Rd",
            "street_address_2": "Unit D",
            "city": "North York",
            "postal_zip": "M3B 2T3",
            "region": "Ontario",
            "country": "CA",
            "notes": "",
            "lead_source": "",
            "source_page": "",
            "custom_meta": "updated meta",
            "profile_picture": "https:\/\/secure.gravatar.com\/avatar\/5658ffccee7f0ebfda2b226238b1eb6e?s=300&d=mm&r=g"
        },
        "tags": [],
        "files": []
    },
    "status": "success",
    "message": "Contact updated successfully."
}
Was this article helpful to you? Yes No

How can we help?