web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / shell is not defined i...
Power Pages
Unanswered

shell is not defined in web api update

(1) ShareShare
ReportReport
Posted on by 11

Hi, 

 

I'm trying to make an update from a web page in a table in dataverse from my custom portal when I select a panel, but I'm getting always the error: "shell is not defined" in the wrapper function.

 

 

<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">
 <title></title>
 <link rel="icon" type="image/x-icon" href="../favicon.ico">
 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 <link rel="stylesheet" href="~/style.css">
 <script src="~/jquery.min.js"></script>

 <script>
 (function (webapi, $) {
 function safeAjax(ajaxOptions) {
 var deferredAjax = $.Deferred();
 shell.getTokenDeferred().done(function (token) {
 // add headers for AJAX
 if (!ajaxOptions.headers) {
 $.extend(ajaxOptions, {
 headers: {
 "__RequestVerificationToken": token
 }
 });
 } else {
 ajaxOptions.headers["__RequestVerificationToken"] = token;
 }
 $.ajax(ajaxOptions)
 .done(function (data, textStatus, jqXHR) {
 validateLoginSession(data, textStatus, jqXHR, deferredAjax.resolve);
 }).fail(deferredAjax.reject); //AJAX
 }).fail(function () {
 deferredAjax.rejectWith(this, arguments); /*on token failure pass the token AJAX and args*/
 });
 return deferredAjax.promise();
 }
 webapi.safeAjax = safeAjax;
 })(window.webapi = window.webapi || {}, jQuery)
 </script>

 <script>
 $(document).ready(function () {
 
 sidepanel.on('click', '.js-evt-save', function () {
 
 var dataObject = {
 "new_field1": 1,
 "new_field2": 2
 };

 webapi.safeAjax({
 type: "PATCH",
 url: "/_api/new_myentity(549b6ebf-00f6-eb11-94ee-000d3ab2493f)",
 contentType: "application/json",
 data: JSON.stringify(dataObject),
 success: function (res) {
 debugger;
 console.log(res)
 },
 error: function (xhr) {
 debugger;
 }
 });
 })
			})
 </script>

 

 

HoracioCrespo_0-1629755981104.png

 

the portal version is: 9.3.7.14 and I already created the web role, entity permission and settings. 

I tried with the wrapper inside the $(document).ready but nothing works. 

I'm not logged in the portal, I'm as anonymous. Can be it a problem ?

 

Has anyone had the same problem ?

 

Thanks in advance

 

Categories:
I have the same question (0)
  • ragavanrajan Profile Picture
    7,044 Most Valuable Professional on at

    Hi @HoracioCrespo 

     

    In your code, there is a method "

    validateLoginSession

     

    which indicates it requires login. 

     

    However, all your queries clearly answered in @OOlashyn  blog 

     

    https://www.dancingwithcrm.com/powerapps-portal-web-api-deep-dive/ 

     

    I would strongly recommend you to read especially about shell function and how Web API works. 

    Hope it gives you some clarity. 


    ------------

    If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

  • OOlashyn Profile Picture
    3,498 Most Valuable Professional on at

    Hi @HoracioCrespo ,

    As @ragavanrajan  mentioned I wrote a deep dive article about Web API so check it out to find out more.

    Web API wrapper doesn't care if you anonymous or authorized user. All it cares about is proper entity permissions when executing requests (so if you don't have them you will receive an error). This error looks more like a problem with portal as shell is provided by it. What I advise you to do is create a web template that will have only a script tag with web api wrapper. Then check if a page with that template throws the error as well. If it does restart the portal and check again. If the issue still persists please open a ticket with Microsoft support. If the problem goes away try again to add the web api to your main template.

  • vduggineni91 Profile Picture
    6 on at

    Hi, Could you able to figure out this issue? I am in the same boat says shell is not defined?

     

    vduggineni91_0-1645655808158.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
rezarizvii Profile Picture

rezarizvii 61

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 40 Most Valuable Professional

#3
11manish Profile Picture

11manish 30

Last 30 days Overall leaderboard