Is it possible to get ContentId and ContentTypeId from a URL?

Former Member
Former Member

I'm trying it implement an external integration with the points service so that users can be awarded points by performing a custom action managed on an external system.  The CTA (call to action)/source of the action might be from a custom page or from a customization embedded within a piece of content, but the logic that will award the points will be hosted elsewhere.

IPointTransactions.Create(string description, int userId, int value, Guid contentId, Guid contentTypeId, PointTransactionCreateOptions options = null) has required parameters of contentId and contentTypeId.  Is there a way to get these values by URL?  That is, is there some service I can call to retrieve an IContent (or an entity that implements that interface) by URL?

I'm trying to write an in-process REST endpoint that won't be too difficult for a remotely hosted web service to use or require too much extra logic to figure out what those arguments should be.

  • Former Member
    0 Former Member

    Apis.Get<Telligent.Evolution.Extensibility.Api.Version1.IUrl>().ParsePageContext(url) will return a list of the items in Context for a page.  However, the returned objects won't tell you what the "Content" for the page is, you will need to work out some logic to figure this out.  We typically use this method when we know what we are looking for (what user is in context for this url).  It is not used anywhere to generically determine what content is the content for this page.

     

    One thing to look out for when working with ContextItems is Relationship.  For instance, if you pass a wiki page url to this method the returning ContextItems will often contain 2 wiki pages (the page and its parent).  The parent having a relationship equal to "Parent".

    Quick idea of the logic that may be needed to work out the "Content" of the page:

    var pageContext = Apis.Get<Telligent.Evolution.Extensibility.Api.Version1.IUrl>().ParsePageContext(url);
    if (pageContext != null)
    {
        if (pageContext.ApplicationTypeId != null)
        {
            var items = pageContext.ContextItems.Find(a => a.ApplicationTypeId == pageContext.ApplicationTypeId && a.ContentTypeId != pageContext.ApplicationTypeId);
            if (items != null)
            {
                //if 1 item its probably your page content
                //if multiple items it is probably the one with empty relationship
            }
            else  //there was no content for the specific application, so maybe on an application level page
            {
                items = pageContext.ContextItems.Find(a => a.ApplicationTypeId == pageContext.ApplicationTypeId && a.ContentTypeId == pageContext.ApplicationTypeId);
                if (items != null)
                {
                    //if 1 item your are likely on an application page 
                }
            }
            //etc
        }
        else if (pageContext.ContainerTypeId != null) 
        {
            //etc
        }
    }

  • Former Member
    0 Former Member in reply to Former Member

    That worked.  I have to supply a type (e.g. "Page", "ForumThread", etc.) to filter the context items, but that's fine.

    Thanks for your help!

  • I can vouch for this method.. we're using this to good effect across a number of our customisations & it works well.