Retrieve Riddle details
You can use the Riddle API to retrieve details of a specific Riddle. Riddle
Step 1
Create an API Access Token here: Access Token. Important: Delete this token after you finish testing here.
Example Symfony PHP controller
This is an example of how you can retrieve the details of a Riddle using the Riddle API in a Symfony PHP controller.
<?php
// src/Controller/RiddleApiController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
class ResponseDTO
{
public string $message;
public int $status;
public $data;
}
class RiddleApiController extends AbstractController
{
#[Route('/api/riddle/details/{uuid}', name: 'app_riddle_details', methods: ['POST'])]
public function getRiddleDetails(string $uuid, Request $request, HttpClientInterface $httpClient, SerializerInterface $serializer): JsonResponse
{
// read the access token from the request json body post
$data = json_decode($request->getContent(), true);
$riddleAccessToken = $data['riddleAccessToken'] ?? null;
if ($riddleAccessToken === null) {
return new JsonResponse(['message' => 'Missing riddleAccessToken'], 400);
}
$client = $httpClient->withOptions([
'base_uri' => 'https://www.riddle.com',
'headers' => [
'X-RIDDLE-BEARER' => 'Bearer ' . $riddleAccessToken,
]
]);
$response = $client->request(
'GET',
'/api/v3/riddle/' . $uuid
);
$statusCode = $response->getStatusCode();
$responseDTO = new ResponseDTO();
$responseDTO->status = $statusCode;
if ($statusCode !== 200) {
$responseDTO->message = 'Error';
return new JsonResponse($responseDTO, $statusCode);
}
$content = $response->toArray();
$responseDTO->message = 'Success';
// return unfiltred data
$responseDTO->data = $content['data'];
return new JsonResponse($responseDTO, $statusCode);
}
}