AdvantageCMS.Core.Common.BaseClasses Namespace
Advantage CSP

AdvantageApiRequest<(Of <(<'TReturnResult>)>)> Class

AdvantageApiRequest returns the result of an API call from the client of objects that have been defined as API accessible.

Namespace:  AdvantageCSP.API.Request
Assembly:  AdvantageCSP.API (in AdvantageCSP.API.dll)

Syntax


public static class AdvantageApiRequest<TReturnResult>

Type Parameters

TReturnResult
The type of the t return result.

Remarks


Client side usage

Enumerations
Sort direction:

  • Values: asc, desc
  • var advDirection = Object.freeze({ Asc: 'asc', Desc: 'desc' });

Data types:

  • Values: string,date,boolean,decimal,integer,uniqueidentifier
  • var advDataType = Object.freeze({ String: 'string', Date: 'date', Boolean: 'boolean', Decimal: 'decimal', Integer: 'integer', UniqueIdentifier: 'uniqueidentifier' });

Comparison:

  • Values: equals, notequals, like, notlike, greaterthan, greaterorequals,lessthan,lessorequals, all
  • var advCompare = Object.freeze({ Equals: 'equals', NotEquals: 'notequals', Like: 'like', NotLike: 'notlike', GreaterThan: 'greaterthan', GreaterOrEquals: 'greaterorequals', LessThan: 'lessthan', LessOrEquals: 'lessorequals', All: 'all' });

Usage Notes
Implement the routing (and optional security handler in Global.asax)

  • Using secure methods requires you to return a successful 'AdvantageAuthResponse' from the method "AuthenticateRequest" implemented in the handler. You must also set the Authenticate = true for the API call;
  • Optional indexing and filtering parameters can be sent via the 'data' parameter.
  • Index (optional index defined on the object) {"Key":"indexname","DataType":"index data type","Comparison":"comparitor","Value":"value to compare"}
  • Filter (optional array of 'where' criteria) [{"Key":"field name","DataType":"filter data type","Comparison":"comparitor","Value":"value to compare"}]
  • SortList (optional array of sorting criteria) [{"field name","direction"}] FieldList (optional array of fields to populate) [{"field name"}] MaxRecords (optional maximum records to return '0' is all) SkipRecords (optional records to skip '0' is none)
  • MaxRecords (optional maximum records to return '0' is all)
  • SkipRecords (optional records to skip '0' is none)

Authentication
Authentication is used via the implementation of the AdvantageSecureContentControllerHandler. This is a messaging handler that needs to be registered when you register the routing for the API in the Global.asax.

Error Codes

  • 401 secure methods must implement the 'AdvantageSecureContentControllerHandler' and return successful security request.
  • 500 unable to access the API

Examples


Example of Calling the API for an object called "News" and an the language "en"

html
<head runat="server">
       <title></title>
       <style>
           th, td {padding: 15px;vertical-align: top;}
           table {margin: 0 auto;border-collapse: separate;border-spacing: 5px;border-collapse: collapse;border-spacing: 0;}
       </style>
   </head>
   <body>
       <table cell>
           <tr>
               <td><h1> API Field List</h1></td>
               <td>&nbsp;</td>
               <td > <h1> Get Record By ID</h1></td>
           </tr>
           <tr>
               <td>Select fields (blank for all)</td>
               <td>&nbsp;</td>
               <td>Enter a record Id</td>
           </tr>
           <tr>
               <td>
                   <select multiple="multiple" id="fieldList" style="height: 300px;">
                       <option value="Headline">Headline</option>
                       <option value="LongDescription">LongDescription</option>
                       <option value="Author">Author</option>
                       <option value="ShortDescription">ShortDescription</option>
                       <option value="PublishDate">PublishDate</option>
                       <option value="Source">Source</option>
                       <option value="CardImage">CardImage</option>
                       <option value="HeroImage">HeroImage</option>
                       <option value="Tags">Tags</option>
                       <option value="CTALinkField">CTALinkField</option>
                       <option value="CTALinkLabel">CTALinkLabel</option>
                       <option value="newsCategory">newsCategory</option>
                       <option value="newsType">newsType</option>
                   </select>
               </td>
               <td>&nbsp;</td>
               <td>
                       <input type="text" width="200px;" id="txtMasterId" />
               </td>
           </tr>
           <tr>
               <td><button id="callGetNews" onclick="getNews();">Get All News Items</button></td>
               <td>&nbsp;</td>
               <td><button id="callGetNews" onclick="getNewsById();">Get Single News Item</button></td>
           </tr>
       </table>
       <p><pre id="output" style="background: #fff;"></pre></p>

   </body>
   </html>
JavaScript
//Reference the client library
   <script src="AdvantageCMS.Resource.WebResource.axd?d=AdvantageAPI.js" type="text/javascript"></script>
   <script>

       //Function to get all news items with only the fields selected (optional)
       function getNews() {
           //Create request
           var req = new AdvContentRequest("News", "en");
           // Lopp through field list (optional)
           var fieldList = document.getElementById("fieldList");
           for (var i = 0; i < fieldList.options.length; i++) { if (fieldList.options[i].selected == true) req.AddField(fieldList.options[i].value); }
           // Request the content and reference the promise for the success and failure result.
           advGetContent(req, showResult, showResult);

           // for a syncronis request, use the line below
           //var result = await advGetContent(req);
       }

       //Function to retrieve a specific record
       function getNewsById() {
           var req = new AdvContentRequestById("News", "en", document.getElementById("txtMasterId").value);

           advGetContent(req, showResult, showResult); //Get the data.
       }




       function showResult(resp) {
           var pretty = JSON.stringify(resp, undefined, 2);
           $('#output').html("<p>" + pretty + "</p>");
           document.getElementById('output').value = pretty;
       }



   </script>

Inheritance Hierarchy


Object
  AdvantageCSP.API.Request..::..AdvantageApiRequest<(Of <(<'TReturnResult>)>)>