Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

shell is not defined in web api update



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">

    <meta charset="UTF-8">
    <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>

        (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;
                        .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)

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

                    type: "PATCH",
                    url: "/_api/new_myentity(549b6ebf-00f6-eb11-94ee-000d3ab2493f)",
                    contentType: "application/json",
                    data: JSON.stringify(dataObject),
                    success: function (res) {
                    error: function (xhr) {





the portal version is: 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


Super User
Super User

Hi @HoracioCrespo 


In your code, there is a method "



which indicates it requires login. 


However, all your queries clearly answered in @OOlashyn  blog 


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.

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.

If you find this post helpful consider marking it as a solution to help others find it.
New Member

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




Helpful resources

Carousel Community Blog

Check out the Community Blog

Read all about the most recent blogs in the community!

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Carousel News & Announcements

What's New in the Community?

Check out the latest News & Events in the community!

Users online (4,398)