TransWikia.com

Getting Events from Solspace Calendar using Element API

Craft CMS Asked on February 28, 2021

I am trying to pull the events from my calendar or calendars through the element api but I am running into an issue with the element type. I found an older post that gave examples but they no longer function correctly. When I try to fetch the data I get this error {"error":{"code":404,"message":"Endpoint has an invalid elementType"}}.

I tried all the examples given in the link and as many other permutations as I could think of to fix the element type but to no avail. Here is the code I have right now:

use SolspaceCalendarCalendar;

return [
    'endpoints' => [
        'api/events.json' => function() {
            return [
                'elementType' => Entry::class,
                'transformer' => function(Calendar_EventModel $event) {
                  $exceptions = [];
                  foreach($event->exceptions as $exception) {
                    $exceptions[] = $exception->date;
                  }

                  return [
                    'id' => $event->id,
                    'title' => $event->title,
                    'calendarId' => $event->calendarId,
                    'slug' => $event->slug,
                    'startDate' => $event->startDate,
                    'endDate' => $event->endDate,
                  ];
                }
            ];
        }
    ]
];

Any suggestions would be greatly appreciated. Thanks!

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP