Retrieve Riddle list
You can use the Riddle API to retrieve all your Riddles. Riddle list
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 create an API client in PHP with a Symfony framework.
<?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 RiddleDTO
{
public string $UUID;
public string $title;
public string $type;
}
class RiddleApiController extends AbstractController
{
#[Route('/api/riddle/list', name: 'app_riddle_list', methods: ['POST'])]
public function getRiddleList(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(
'POST',
'/api/v3/riddle/list',
[
'json' => [
'status' => 'published',
]
]
);
$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';
$responseDTO->data = $serializer->deserialize(
json_encode($content['data']),
RiddleDTO::class . '[]',
'json'
);
return new JsonResponse($responseDTO, $statusCode);
}
}