CMS API: getUserTransactions - Transation Length

Options
Based on logging the client API responses for getUserTransactions, I've encountered that when there is more then one transaction, the api ‘transaction’ object becomes an array and you have to access the values differently.


If there’s one transaction, you can access the donation amount like this
getConsTransactionsResponse.transaction.donation_detail.campaign.title


If there is more than one transaction, you’d have to access like this
getConsTransactionsResponse.transaction[0].donation_detail.campaign.title

getConsTransactionsResponse.transaction[1].donation_detail.campaign.title



I'm assuming the API response is structured the same when I access it through the CMS syntax code. Currently i have the following code to loop around getConsTransactionsResponse.transaction and pull the campaign Ids out.

<t:list id="openApi.getConsTransactionsResponse.transaction" >

<t:if test="length == index">

<t:set id="last_donation_id" value="donation_detail.campaign.id" />

<t:set id="last_donation_campaign" value="donation_detail.campaign.title" />

</t:if>

</t:list>



When there are multiple transactions this works as expeted. When there is only one transaction, it doesn’t loop through and therefore doesn’t set a campaign ID.


In the client side API I can account for this, but all of my attempts to test getConsTransactionsResponse.transaction for it’s length have failed. I'd like to do something like this:

<t:data name="openApi" class="convioApi" apiName="SRConsAPI" method="getUserTransactions" includeConsId="true"/>

<t:set id="len" value="openApi.
getConsTransactionsResponse.transactions.length" />

Transactions Length: <t:value id="len" />


And then use and if/else statement to determine how the campaign ID will be set. Has anyone found a way around this?


Tagged:

Categories