$webserviceURL, ]); $response = $client->post('v2.php', [ 'form_params' => [ 'action' => 'authenticate', 'username' => $webserviceUsername, 'password' => $webservicePassword, ], ]); if ($response->getStatusCode() !== 200) { throw new Exception('Entry denied with code : '.$response->getStatusCode()); } $jsonResponse = json_decode($response->getBody()->getContents()); if ($jsonResponse->error) { throw new Exception('Authentication failed because : '.$jsonResponse->message); } return $jsonResponse->data->apiKey; } /** * @param $apiKey * @param $courseId * @param $threadId * * @throws Exception * * @return array */ function getCourseForumThread($apiKey, $courseId, $forumId, $threadId) { global $webserviceURL; global $webserviceUsername; $client = new Client([ 'base_uri' => $webserviceURL, ]); $response = $client->post( 'v2.php', [ 'form_params' => [ // data for the user who makes the request 'action' => 'course_forumthread', 'username' => $webserviceUsername, 'api_key' => $apiKey, 'course' => $courseId, 'forum' => $forumId, 'thread' => $threadId, ], ] ); if ($response->getStatusCode() !== 200) { throw new Exception('Entry denied with code : '.$response->getStatusCode()); } $content = $response->getBody()->getContents(); $jsonResponse = json_decode($content, true); if ($jsonResponse['error']) { throw new Exception('cant get course documents because : '.$jsonResponse['message']); } return $jsonResponse['data']; } $apiKey = authenticate(); //Get details about a specific forum thread. $courseForumThread = getCourseForumThread($apiKey, 1, 1, 1); echo json_encode($courseForumThread);