1. Home
  2. Docs
  3. REST API V2
  4. Contact API
  5. PUT/PATCH Method

PUT/PATCH Method

PUT/PATCH Methods play a vital role in managing contacts. Using this HTTP method you can update existing contacts, apply tags to a contact and remove tags from the contact.

Note: You can perform only one operation at a time.

Updating a Contact

To update details of a contact the contact_id is required. So you need to append the contact_id to your PUT/PATCH url. The following example update contact we just created.

http://yoursite.com/wp-json/gh/v2/contact?key=[public_key]&token=[token]&contact_id=4

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

{
    "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.

{
    "code": "success",
    "message": "Contact updated successfully."
}

Adding Tags With UPDATE

You can also add tags by making PUT/PATCH request to the contact endpoint.

To add tags to a specific contact you need the contact_id appended to the URL and an to pass an array of tag names in the JSON body.

You can get tags by querying the tags endpoint, or by looking for the ID in the admin area.

To add tags via the UPDATE method you can pass the following JSON body. in the below request we both update the first name of the contact and pass the “apply_tags” param with a list of either IDs or tag names. When passing a tag name if the tag does not exist it will simply create the tag and add it.

{
    "contact" : {
         "first_name" : "john"
     },
    "apply_tags" : [ 
        1, 
        2, 
        3, 
        "user", 
        "confirm" 
    ]
}    

This request apply tags and returns following response.

{
    "code": "success",
    "message": "tag(s) applied successfully."
}

Removing Tags with UPDATE

Similarly, remove tags is the same however we pass the “remove_tags” param instead.

{
    "remove_tags" : [1,2,3,"user","confirm"]
}    
Was this article helpful to you? Yes No

How can we help?