Code Snippets for Portal Pages

How to Retrieve a User’s First and Last Names for Portal Page Salutation

To retrieve a user's first and last names, fetch the response object from the /index/index/user-info/ajax/Y endpoint and use the response.first_name and response.last_name properties. Example ajax request:

$.ajax({"url":'/index/index/user-info/ajax/Y'})
  .done(function(response){  
    console.log(response.first_name+' '+response.last_name);
 })

Example of the full response object:  

{
  "username": "tom",
  "first_name": "Tom', 
  "last_name": "Crawford", 
  "display_name": "Tom Crawford", 
  "is_administrator": "Y", 
  "is_power_user": "N", 
  "is_manage_pages_privilege": "Y", 
  "groups": [
    {
      "group_id": "1",
      "name": "Default Group",
      "ldap_organizational_unit": ""
    }
  [
}

How to Get Dataset Data

To retrieve data from a Dataset, use the /api/dataset_data?dataset=<Dataset ID> endpoint and replace <Dataset ID> with the ID of a Dataset. The returned object contains two properties: data and metadata storing Dataset's data and column names with their data types.

Example ajax request:

$.ajax({
        type: 'GET',
        url: '/api/dataset_data?dataset=568',
        dataType: 'JSON',
        success: function (data) {
            console.log(data);
        }
    });

Example response:

{
  "data": [
     {
      "Name": "User5",
      "Country": "USA",
      "Customer ID": "3",
      "Items Purchased": "22"
     },
     {
      "Name": "User7",
      "Country": "Canada",
      "Customer ID": "3",
      "Items Purchased": "10"
     },
     {
      "Name": "User8",
      "Country": "Italy",
      "Customer ID": "3",
      "Items Purchased": "4"
     }
     ],
    "metadata": [
    {
      "name": "Name",
      "type": "text"
    },
    {
      "name": "Country",
      "type": "text"
    },
    {
      "name": "Customer ID",
      "type": "numeric"
    },
    {
      "name": "Items Purchased",
      "type": "numeric"
    }
  ]
}