Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I looked in the documentation but I can't seem to find a way to add a contact to a group using the API.
Open API Explorer - Support menu > Developer > API Explorer and use GroupContact API to add contacts to group. See an eg in the screenshot below -
Support menu > Developer > API Explorer
API formed for PHP is -
$result = civicrm_api3('GroupContact', 'create', [
'group_id' => <group_id>,
'contact_id' => <contact id>,
Required, but never shown