AdvantageCMS.Core.Common.BaseClasses Namespace
Advantage CSP

API Request By ID

Making an API request requires no special framework. The basics for the request require:

  • Reference the JavaScript library.
  • Create the API request object and fill parameter
  • If the API is marked as secure, Authenticate must be set to 'true'
  • Make the synchronous call OR specify the callback functions (success, failure)

Secure API


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.

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 client API

Return Value


Return values for the API are standardized in the following Json Object

  • Data - > Item
  • Error -> Error message (nullable)
  • ResponseCode -> 200, 403, 404, 500

API Return Object

Example


html
<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>Enter Record ID or SEO-Name</h1></td>
             </tr>
             <tr>
                 <td>
                     <input type="text" width="200px;" id="txtMasterId" />
                 </td>
             </tr>
             <tr>
                 <td><button id="callGetNews" onclick="getNewsById();">Get News Item</button></td>
             </tr>
         </table>
         <p><pre id="output" style="background: #fff;"></pre></p>

     </body>     </html>

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

    function getNewsById() {
       // Create request
        var req = new AdvContentRequestById("News", "en", document.getElementById("txtMasterId").value);

        // Request the content and reference the promise for the success and failure result.
      advGetContent(req, showResult, showResult); //Get the data.

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


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