odatasitefinity

How to get full content URL of content item using Sitefinity oData (Web Service) and add it to response data?


I am trying to use Sitefinity's Web services functionality to query a list of content items from the database, in this case, a list of Events. So far I've successfully been able to get a response which is an array of objects representing the data of my Events. Here is one example of an event object:

{"Id":"f3fd8515-3279-6e2e-aa53-ff00001c1b3c",
"LastModified":"2021-05-28T16:40:08Z",
"PublicationDate":"2021-05-28T16:40:08Z",
"Title":"Future event 1",
"Description":"",
"DateCreated":"2021-05-28T16:40:08Z",
"IncludeInSitemap":true,
"UrlName":"future-event-1",
"MetaTitle":"",
"MetaDescription":"",
"ToggleCalendarBtns":true,
"CTABtnContext":"",
"CTABtnText":"Event Website",
"CTABtnURL":"#",
"AllowComments":true,
"EventStart":"2021-07-01T17:00:00Z",
"EventEnd":"2021-07-01T18:00:00Z",
"ContactEmail":null,
"ContactWeb":null,
"Street":"",
"City":"",
"Country":"Virtual",
"State":"",
"ContactName":"",
"ContactCell":"",
"ContactPhone":"",
"Content":"",
"Summary":"",
"IsRecurrent":false,
"RecurrenceExpression":null,
"TimeZoneId":"Central Standard Time",
"AllDayEvent":false,
"Location":"",
"ParentId":"62e1290c-2f0f-4a5d-8def-6c46fc900657",
"EventStartUtcOffset":-300.0,
"EventEndUtcOffset":-300.0,
"EventStartWithOffset":"2021-07-01T12:00:00Z",
"EventEndWithOffset":"2021-07-01T13:00:00Z"}

Is it possible to modify Sitefinity's web service functionality to add an additional property to this data object that gets the actual URL of this content item? What I mean by this is the "UrlName" property that is returned is only a partial fragment of the Event's full URL required to view it on a page:

UrlName property: future-event-1

Full Event Url: /2021/07/01/default-calendar/future-event-1

How can I get Sitefinity's oData response to include the Full event Url like in the second example above, rather than just the UrlName slug?


Solution

  • Here is what you can do:

    1. Go to Administration > Settings > Advanced > WebServices > Routes > Frontend > Services > {your service} > Types > Telerik.Sitefinity.Events.Model.Event > Property mappings

    2. Create new mapping of type PersistentPropertyMapping (you will see it in a dropdown when you click Create New).

    3. Enter ItemDefaultUrl for Persistent Name and Name. Save.

    Now, when you query data for a single event, e.g.:

    /api/events/events/8dab99e3-fed6-4e8e-887f-e23f56ec32c4

    or all events

    /api/events/events

    the new property will be included in the response and should contain what you need.