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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Power Apps Portal Web API "shell is not defined"

(0) ShareShare
ReportReport
Posted on by 5

The documentation for the portals web API includes this JavaScript wrapper for calling the API from within a portal construct.

(function(webapi, $){
	function safeAjax(ajaxOptions) {
		var deferredAjax = $.Deferred();

		shell.getTokenDeferred().done(function (token) {
		


Although my portal version is well above the required version 9.2.6.41 and I believe I've set up the pre-requisites, and this code block does get entered, I always get an error "shell is not defined" from the shell line.

Does anyone know what could cause that?


I have the same question (0)
  • Suggested answer
    CU29100325-0 Profile Picture
    5 on at

    After further attempts, I think the issue is that shell is not available from within Web Form steps.

    In fact, I am able to remove the token-getting code and execute a delete via ajax without it. It seems that when in a form context, the token is already taken care of and so we don't need the shell to get it.

    (function(webapi, $){
    	function safeAjax(ajaxOptions) {
    		var deferredAjax = $.Deferred();
    
            // removed call to shell.getTokenDeferred()
    
    		$.ajax(ajaxOptions)
    				.done(function(data, textStatus, jqXHR) {
    					validateLoginSession(data, textStatus, jqXHR, deferredAjax.resolve);
    				}).fail(deferredAjax.reject);
    
    		return deferredAjax.promise();	
    	}
    
    	webapi.safeAjax = safeAjax;
    
    })(window.webapi = window.webapi || {}, jQuery)
    
    webapi.safeAjax({
    		type: "DELETE",
    		url: "/_api/annotations(00000000-0000-0000-0000-000000000000)",
    		contentType: "application/json",
    		success: function (res) {
    		},
    		error: function(res) {
    			console.log("error", res);
    		}
      });


    The cookie containing the verification token gets sent with the ajax request anyway.

    pastedimage1611975245226v1.png

  • Israel de la rosa Profile Picture
    5 on at

    this works, another alternative would be run the script until the dom is completely loaded...

    $(function(){
    
    	(function(webapi, $){
    		function safeAjax(ajaxOptions) {
    			var deferredAjax = $.Deferred();
    				
    			$.ajax(ajaxOptions)
    				.done(function(data, textStatus, jqXHR) {
    					validateLoginSession(data, textStatus, jqXHR, deferredAjax.resolve);
    				}).fail(deferredAjax.reject); //AJAX
    		
    	
    			return deferredAjax.promise();	
    		}
    		webapi.safeAjax = safeAjax;
    	})(window.webapi = window.webapi || {}, jQuery)
    
    		
    	webapi.safeAjax({
    			type: "GET",
    			url: "/_api/cbs_estimationlines",
    			contentType: "application/json",
    			success: function (res) {
    					console.log("completed")
    					console.log(res);
    
    		}
    	});
    	
    })

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 Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 176 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 139

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans