Using consId from an API call within a s-tag

Options
I'm trying to use the consId I've retrieved from an API call within a s-tag.


Example: [[S48:2647-" + this.consId + ":cons.custom_string13]]


This does not seem to be working. Is this possible? What am I missing?


A bit more information about what we are trying to do:


Within the participant center we want to display the team roster to team captains which includes the team member's name and their selected t-shirt size (chosen during registration).


We've discovered that we can create this list of team members using the getParticipants API call and filter by team_name.


We've also discovered that we can grab the participants response to t-shirt size which is stored on their constituent record using [[S48:2647-5312121:cons.custom_string13]]


But we are unable to dynamically pull in the consId for each participant in the list.


Here's a peek at the code we are using:


<script type="text/javascript">


jQuery(document).ready(function()

{

getRoster();

});


function getRoster(){


jQuery("#results").html("<p>Loading...</p>");


var requestString =

'https://secure3.convio.net/****/site/CRTeamraiserAPI?' +

'method=getParticipants' +

'&v=1.0' +

'&api_key=****' +

'&response_format=json' +

'&suppress_response_codes=true' +

//'&fr_id=[[S80:trID]]' +

'&fr_id=****' +

'&list_sort_column=last_name' +

'&list_ascending=true' +

'&team_name=****' +

'&first_name=%%%';


var requestURL = "AjaxProxy?auth=[[S86:true]]&cnv_url=" + escape(requestString);


jQuery.getJSON(requestURL,function(data)

{

if(data.errorResponse)

{

jQuery("#results").html("<p>(" + data.errorResponse.message + ")</p>");

} else {


jQuery("#results").html("");


var trObject=data.getParticipantsResponse.participant;



jQuery.each(trObject,function()

{

var memID = this.consId;

jQuery("#results").append("<p><strong>Name:</strong> " + this.name.first + " " + this.name.last + " <strong>ConsID:</strong> " + this.consId + " <strong>T-Shirt Size:</strong> [[S48:2647-" + this.consId + ":cons.custom_string13]] || TESTING [[S48:2647-5312121:cons.custom_string13]] || TESTING 2:" + memID +" </p>");

});


}

});


};


</script>


[[S48:2647-5312121:cons.custom_string13]]

<div id="results"></div>


***I've hidden the shortname, API key and a few other pieces - but they are there on the live test***


Any help would be greatly appreciated! :)

@NoahCooper
Tagged:

Comments

  • That won't work because S tag is a server-side while the API is a REST based API that is a client-side (i.e. Javascript).


    Server side always get processed first before the client-side, thus it never would make it in time to retrieve the returned API result. However, for general note -- the other direction would work meaning you could hold S-tag value in a Javascript variable -- that will work.


    Haven't read all the details on your posting just yet-- but I was wondering why not retrieving cons ID through S1 tag? you could do that instead of doing it through API especially if you are looking for a logged in user cons ID. When you nest multiple S tag, make sure that you use E on the outer S-tag so in your example that would look in this fashion below:

    [[E48:2647-[[S1:cons_id]]:cons.custom_string13]]


    regards,

    Daniel

    Kate Gollogly:

    I'm trying to use the consId I've retrieved from an API call within a s-tag.


    Example: [[S48:2647-" + this.consId + ":cons.custom_string13]]


    This does not seem to be working. Is this possible? What am I missing?


  • You are using getParticipants. That method can return the consId.

    <getParticipantsResponse xsi:schemaLocation="http://convio.com/crm/v1.0 http://service.convio.net/xmlschema/crm.public.v1.xsd" xmlns="http://convio.com/crm/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <totalNumberResults>3</totalNumberResults>
    <participant>
    <name>
    <first>Participant</first>
    <last>Sample01</last>
    </name>
    <aTeamCaptain>false</aTeamCaptain>
    <teamName/>
    <donationUrl>http://example.com/donateurl</donationUrl&gt;
    <personalPageUrl>http://example.com/personalpageurl</personalPageUrl&gt;
    <teamPageUrl/>
    <consId>1001000</consId>
    <personalPagePrivate>false</personalPagePrivate>
    <amountRaised>5180</amountRaised>
    <goal>105060</goal>
    <eventName>Event 1000</eventName>
    <eventId>1000</eventId>
    </participant>
    But I don't think you can get a custom cons field using getParticipants, or any other method, for anyone but yourself.


    One idea is to put the collection of team member cons Ids (getTeamMembers might be faster for this) into an array and then populating each row in your results from a JSONP call to a "roll-your-own-API". Noah wrote a blog post about this once a long ways back. The basic idea is that you build a PageBuilder page which serves up nothing but some JSON (so you'll need to add the url param to turn off the wrapper when you make a call the 'API'.) That PB page populates the data by using the cons id that you pass to it via a query string param in the calling URL. Just don't serve anything sensitive, cause there isn't any security here.


    So the request url would look like this as you walked through the array of team member ids.


    var requestURL = "https://secure3.convio.net/ABC/site/SPageServer?pagename=JSONPTest&consid=" + myConsIdList[index] + "&printer_friendly=1";


    And each call would return a page of JSON from a PB page coded like this:


    {

    "screenname" : [[E48:2647-[[S334:consid]]:screenname]];

    "shirtSize" : [[E48:2647-[[S334:consid]]:cons.custom_string13]];

    }


    Then append each result to your roster.


    Hope that makes sense!


    -B


    EDIT: clarity
  • Ok as I read further what you are trying to achieve, here are some steps / ideas you may try -- you may probably need two pagebuilders at minimum and also depending on how you are presenting the Participant Center 2 (PC2) -- this note is assuming that you have a PC2 as a stand alone (not an embedded through iframe as result of that S409 tag)

    1. ) Get the team-id through S48. Put this into a pagebuilder -- this pagebuilder be included/loaded to your Participant Center (i.e. through jQuery load) and when a team captain logs into his/her PC2, that page would surely return the team ID.


    Note the use of S334 to dynamically retrieve the FR_ID from the fr_id URL parameter that always get returned within the Participant Center 2 URL also note why I put that inside of the DIV, so that we could target that DIV to retrieve the content on subsequent steps below


    <div id="myTeamID">[[E48:[[S334:fr_id]]-[[S1:cons_id]]:team-id]]</div>





    2.) Retrieve the text value of that DIV above and Assign the Team ID value you retrieved above to a Javascript variable to be used for filter to the API call of

    getTeamMembers API


    http://open.convio.com/api/#teamraiser_api.getTeamMembers_method.html.


    This API would return those team members saving the effort from having to do extra team name filtering, most importantly it returns the cons_id

    3.) Knowing that client side variables can't be passed for processing at server-side as I mentioned earlier, one of the workaround you could alternatively use -- you might want to use a pagebuilder as placeholder to be called / load (i.e. through jQuery load to load and append into a DIV placeholder x amount of times reflecting the returned records of the above API call, where you could pass the API returned cons ID, first name, last name into / as URL parameters to be appended into that pagebuilder URL. And the content of that pagebuilder is that full set of S-tags


    <h1>Team Member</h1>

    <p>First Name: [[S334:tmfname]]</p>

    <p>Last Name: [[S334:tmlname]]</p>

    <p>T-shirt size:[[E48:[[S334:fr_id]]-[[S334:cid]]:cons_custom_string13]]</p>



    note feel free to change the parameter name to your own if you don't want to keep what's given above, in that above, the tmfname is to hold returned API first name, tmlname is to hold returned API last name, and the cid is to hold your returned cons ID from the API


    Hope it helps,


    Daniel

    Daniel Hartanto:

    That won't work because S tag is a server-side while the API is a REST based API that is a client-side (i.e. Javascript).


    Server side always get processed first before the client-side, thus it never would make it in time to retrieve the returned API result. However, for general note -- the other direction would work meaning you could hold S-tag value in a Javascript variable -- that will work.


    Haven't read all the details on your posting just yet-- but I was wondering why not retrieving cons ID through S1 tag? you could do that instead of doing it through API especially if you are looking for a logged in user cons ID. When you nest multiple S tag, make sure that you use E on the outer S-tag so in your example that would look in this fashion below:

    [[E48:2647-[[S1:cons_id]]:cons.custom_string13]]


    regards,

    Daniel

    Kate Gollogly:

    I'm trying to use the consId I've retrieved from an API call within a s-tag.


    Example: [[S48:2647-" + this.consId + ":cons.custom_string13]]


    This does not seem to be working. Is this possible? What am I missing?


  • LOL - great minds.


    - B
  • two heads are better than one as the saying goes otherwise just killing off some down times at lunch as if there isn't much to do ha :)) Happy Thursday there B!

    Brian Mucha:

    LOL - great minds.


    - B

  • Note that there is an undocumented Content API method called render which can evaluate S-Tags.


    https://secure3.convio.net/myorg/site/CRContentAPI?v=1.0&api_key=MyKey&method=render&content=[[S42:1234:title]]&auth=token


    With luminateExtend, this looks like:


    luminateExtend.api({

    api: 'content',

    data: 'method=render&content=[[S42:1234:title]]',

    requiresAuth: true

    })


    Keep in mind that if you're putting this content into a page that runs through the Luminate Online template engine, you must use L-Tags to avoid the S-Tag being evaluated, e.g.


    luminateExtend.api({

    api: 'content',

    data: 'method=render&content=[[LL]]S42:1234:title[[LR]]',

    requiresAuth: true

    })
  • Wow! That is going to be a post we come back to a lot in the future, Noah. Thanks!!
  • Thanks Noah for this -- bookmarked as this would make life much simpler onward.

    Noah Cooper:

    Note that there is an undocumented Content API method called render which can evaluate S-Tags.


    https://secure3.convio.net/myorg/site/CRContentAPI?v=1.0&api_key=MyKey&method=render&content=[[S42:1234:title]]&auth=token


    With luminateExtend, this looks like:


    luminateExtend.api({

    api: 'content',

    data: 'method=render&content=[[S42:1234:title]]',

    requiresAuth: true

    })


    Keep in mind that if you're putting this content into a page that runs through the Luminate Online template engine, you must use L-Tags to avoid the S-Tag being evaluated, e.g.


    luminateExtend.api({

    api: 'content',

    data: 'method=render&content=[[LL]]S42:1234:title[[LR]]',

    requiresAuth: true

    })

  • Thanks for the reply!


    @NoahCooper Where might I be able to find some documentation on these undocumented methods (the irony behind that question lol) and L-tags? Any point of reference to work of would be great!


    Thanks all for your contribution to this! We'll be sure to share what we come up with.



    Noah Cooper:

    Note that there is an undocumented Content API method called render which can evaluate S-Tags.


    https://secure3.convio.net/myorg/site/CRContentAPI?v=1.0&api_key=MyKey&method=render&content=[[S42:1234:title]]&auth=token


    With luminateExtend, this looks like:


    luminateExtend.api({

    api: 'content',

    data: 'method=render&content=[[S42:1234:title]]',

    requiresAuth: true

    })


    Keep in mind that if you're putting this content into a page that runs through the Luminate Online template engine, you must use L-Tags to avoid the S-Tag being evaluated, e.g.


    luminateExtend.api({

    api: 'content',

    data: 'method=render&content=[[LL]]S42:1234:title[[LR]]',

    requiresAuth: true

    })

  • Good news is we got it working within a page builder page!

    http://cibcrunforthecure.supportcbcf.com/site/PageNavigator/TEST_team_roster_api.html


    But we are now tying to pull this code into the participant center so that team captains can find this information within their pc.


    This has brought about another slew of errors as the pc does not seem to work well with Luminate Extend.


    @NoahCooper, is there a trick to getting Lumiante Extend to work in the participant center?

Categories