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

Notifications

Announcements

No record found.

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

Responsible AI policies

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

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans