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

Community site session details

Session Id : O2KPAaXHhZfzhddrUc4+LB
Power Pages - Power Apps Portals
Unanswered

shell is not defined in web api update

Like (1) ShareShare
ReportReport
Posted on 23 Aug 2021 22:18:22 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

 

I have the same question (0)
  • vduggineni91 Profile Picture
    6 on 23 Feb 2022 at 22:33:42
    Re: shell is not defined in web api update

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

     

    vduggineni91_0-1645655808158.png

     

  • OOlashyn Profile Picture
    3,496 Most Valuable Professional on 24 Aug 2021 at 21:05:25
    Re: shell is not defined in web api update

    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.

  • ragavanrajan Profile Picture
    7,036 Most Valuable Professional on 24 Aug 2021 at 09:48:42
    Re: shell is not defined in web api update

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#2
Lucas001 Profile Picture

Lucas001 48 Super User 2025 Season 2

#3
KevinGador Profile Picture

KevinGador 44 Super User 2025 Season 2

Loading complete