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

Unable to use Web api call in canvas app

Hi All,

I am trying to use web API(link below) call, but the below link says it is only available for Model driven apps.

Any alternate way to use API call in Canvas App? Any suggestion much appreciated.

Solution Sage
Solution Sage

You will need to create standard XMLHttpRequests. This is a sample I posted earlier today (it calls an action within a Model driven app) you will just need to change the baseUrl, query and body contents.


var req = new XMLHttpRequest();
		var baseUrl=this.baseUrl;
var query="/api/data/v9.1/hdn_ValidateLicense";
		return new Promise(function (resolve, reject) {"POST", baseUrl + query, true);
			req.onreadystatechange = function () {
				if (req.readyState !== 4) return;
				if (req.status >= 200 && req.status < 300) {
					// If successful
					try {
						var result = JSON.parse(req.responseText);
						if (parseInt(result.StatusCode) < 0) {
								status: result.StatusCode,
								statusText: result.StatusMessage
					catch (error) {
						throw error;

				} else {
					// If failed
						status: req.status,
						statusText: req.statusText

			req.setRequestHeader("OData-MaxVersion", "4.0");
			req.setRequestHeader("OData-Version", "4.0");
			req.setRequestHeader("Accept", "application/json");
			req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
var body=	"{'ProductName': '"+productName+"'}";


If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".

I really hope that we will get the Xrm.WebApi implemented in Canvas Apps at some point - but it does kind of go against the principle of Canvas Apps - using connections to communicate with CDS.

@ben-thompson this has got me thinking - would this code work in Canvas - wouldn't the user need to be already authenticated with CDS first so that there is a bearer cookie? If you are running on the mobile app I'm not even sure that the bearer cookie would be available? You'd need to do an auth request to get the access token first. And then there is CORS? -

Just gave it a go and managed to call with auth using adal:


config = {tenant: "",clientId :"51f81489-12ee-4a9e-aaae-a2591f45987d"}
adalContext = new AuthenticationContext(config);
(e, accesstoken) => fetch("",
{headers:{"Authorization":"Bearer " + accesstoken}}).then(



Continued Contributor
Continued Contributor

I wrestled with this same issue in a separate thread ( pcf assign output params for canvas app operations ) . Rather than using adal, I decided to push the database operations back up to PowerApps. I could say I did it because I wasn't certain the token would be available without MFA, but really... it's just because I'm lazy.


Within your Canvas app, what you need to do is define one or more Output type params, then give it the data you need to undertake your action (e.g. for an update, the GUID and attributes to update) then you call notifyOutputChanged to let the canvas app know your output is ready.  Back up in your Canvas App, you just put your logic into the OnChange event on the control (which is essentially what you are calling with notifyOutputChanged). Then, your outputs should be available in <controlname>.<outputparamname> so you can do your CDS operations from up here or even in Flow.


Quick note though: a big drawback you're going to run into with this approach is the known bug @HemantG and team are working on where a canvas app caches its embedded pcf and doesn't refresh the control when you update pcf in solution. Because you will be splitting your logic across the pcf and the canvas app, you will likely need to iterate a few times and will need to delete the canvas app and recreate it every time you make a change in pcf. Definitely a big headache, but they are working on a fix and I'm sure it will be available soon.

For now best solution is to use the output and let canvas app store the data. I have used patch in one of my recent exploration to save data to CDS. PCF upgrade issue should be fixed now and you should see PCF update prompt when the app is reopened. We will have more tighter inner loop in future releases for canvas apps. 



Scott, Do you have any other details about how you got this to work? I have the need to load data from CDS in a grid that is aggregated and I can't seem to figure out any other way to do it than this. I did look at what @cchannon and @HemantG provided, but I just don't think I can get the data in Power Apps.


I have tried using msal and adal but in both cases I get to a point where I get the following from the authorize endpoint

AADSTS50050: The request is malformed: invalid format for 'authorization_endpoint' value.  

 and a bunch of calls to "" with a 500 error of 

Returning InternalServerError for resource publishedapp/preloadindex after trying all 1 configured resource origins.

Any help you could provide would be greatly appreciated. 

Helpful resources

PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!


Are Your Ready?

Test your skills now with the Cloud Skill Challenge.


Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (43,042)