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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Uncaught ReferenceErro...
Power Pages
Answered

Uncaught ReferenceError: webapi is not defined

(0) ShareShare
ReportReport
Posted on by 265

hi , 

I am getting this kind of error.

Erandi_1-1708576852668.png

the error is happened with below code. 

Erandi_0-1708576830929.png

Which kind of reasons are caused to above errors?

Thanks

Categories:
I have the same question (0)
  • Verified answer
    Lucas001 Profile Picture
    2,575 Super User 2026 Season 1 on at

    Hi @Erandi ,

     

    the issue is probably exactly what's stated.

    Did you initialize the webApi?

     

    Post the following script at the end of your html of the page you use the webapi in and it should work fine:

    <!--Script to make the webapi work-->
    <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>



    --------------------------------------------------------------------------------------

    Hope that helps.

    If the post solves your problem, please mark it as solution. If it helps, consider a thumbs up.

  • Erandi Profile Picture
    265 on at

    @Lucas001 It is worked thank  you very much

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Valantis Profile Picture

Valantis 37

#2
sannavajjala87 Profile Picture

sannavajjala87 36 Super User 2026 Season 1

#3
Fubar Profile Picture

Fubar 23 Super User 2026 Season 1

Last 30 days Overall leaderboard