Yes for using any Moodle API config.php is a must. Than add any additional libraries you intend to use.
In this case you would need these:
require_once(<relative path to config.php>);
// $course is full couurse object
$completion_info = new completion_info($course);
// $cm is course module object
$completion = $completion_info->update_state($cm, COMPLETION_COMPLETE));