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?


  • Israel de la rosa Profile Picture
    5 on at
    RE: Power Apps Portal Web API "shell is not defined"

    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);
    
    		}
    	});
    	
    })

  • Suggested answer
    CU29100325-0 Profile Picture
    5 on at
    RE: Power Apps Portal Web API "shell is not defined"

    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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,097 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,872 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans