Use API REST to display a dynamic html table

mbouzekoto
Giga Contributor

Hi,

I'm trying to display a dynamic table in my widget. I have two scripts for that, one HTML for the page and one client script to handle data. but when i try to get the data  from my REST API table it does nothing. i checked on internet to find where is my mistake, they said that the header with my authentification informations (Username and password) is missing. But i don't want to put my information in the script. I wonder if anyone have ever been in the same situation and how can i sove it. here is the part of my client script where im trying to catch data's API REST table -->

 

 
$scope.data = {
    fields: ["name", "u_authority_contact", "u_courriel_d_urgence", "u_eligible_for_support"],
    column_labels: { 
        name: "Nom", 
        u_authority_contact: "Contact en autorité", 
        u_courriel_d_urgence: "courriel d'urgence", 
        u_eligible_for_support: "Éligible au support" 
    },
 
    list: [ ]
};
  var tableName = "customer_contact";
 
$http({
        method: 'GET',
        url: instanceUrl + "/api/now/table/" + tableName
    }).then(function(response) {
        // Mise à jour de la liste avec les données récupérées
        $scope.data.list = response.data.result;
    }).catch(function(error) {
        console.error("Erreur lors de la récupération des données :", error);
    });
 
console.log($scope.data.list);

 

and here is the part of my HTML script where i'm trying to display it -->

 

<!-- body -->
<div class="panel-body">
<div class="grid-container" ng-if="data.list.length">
<div class="grid-item" ng-repeat="item in data.list track by item.sys_id">
<span>{{item[field].display_value}}</span>
</div>
<div ng-if="options.show_breadcrumbs == true || data.enable_filter == true" class="filter-breadcrumbs">
<widget id="filter-breadcrumbs-restricted"></widget>
<sp-widget widget="data.filterBreadcrumbs"></sp-widget>
</div>
<div class="alert alert-info" ng-if="!data.list.length && !data.num_pages && !data.invalid_table && !loadingData">
${No records in {{data.table_label}} <span ng-if="data.filter">using that filter</span>}
</div>
<div class="alert alert-info" ng-if="loadingData">
<fa name="spinner" spin="true"></fa> ${Loading data}...
</div>

4 REPLIES 4

jcmings
Mega Sage

Have you setup the outbound REST message via System Web Services > Outbound > REST Message? 

Hi @jcmings ,

No, i haven't setup it. Can you explain what i have to do there please?

Hi @jcmings,

I have set up the outbound REST message. i got a 401 http error. It is the same error that failed my script. i tried to use my admin account which i use to navigate in the SNOW dashbord management but nothing changed. here is the print screen. Do you have any solution to solve it please?

Is there any documentation from the endpoint you're trying to hit? Usually they should provide you with authentication credentials. Sounds like you may need to get that from the endpoint's POC.