API to access MS forms

Occasional Visitor

Looking for an API to access MS forms and pull the survey results on a weekly basis.

39 Replies

@ravipokala an API has been promised for Forms for a long time but has never arrived. The solution is therefore to use a flow in Power Automate to save each form response to a list in SharePoint. You can either see the last week's responses there or you could have another flow with a recurrence schedule trigger set to 1 week. That would get the items created in the list in the last week and do whatever you want to do with it.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

@RobElliott , a fairly good workaround. Unfortunately, Flows are prone to failing now and then and if you miss a response I guess there's no way to re-fetch it in retrospect?

@Martin Dreyer the response will still be in the spreadsheet behind the form, so you've still got the response even if the flow fails for some reason. Over the last 3 years I've found Power Automate to be very reliable and a flows will very rarely fail once you have properly tested it. Power Automate is far more reliable than Forms which, as this form shows, is far more prone to errors and things not working the way they should.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

@ravipokala I'm using VBA + SeleniumBasic-2.0.9.0


You must first open the URL “https://forms.office.com/Pages/DesignPage.aspx” to obtain a token


Then you can call "https://forms.office.com/formapi/DownloadExcelFile.ashx?formid=" + put your form ID Here + "&timezoneOffset=180&minResponseId=1&maxResponseId=1000"


This is working for me

@Leandro_Abade could you please highlight on how did you obtain the token? Did you have to register in app in Azure portal or by some other way. I am implementing something similar and stuck with the first pre-requisite of obtaining token.

Hi @ssahal ! You just need access the URL “https://forms.office.com/Pages/DesignPage.aspx”, then in same section you calls "https://forms.office.com/formapi/DownloadExcelFile.ashx?formid=" + [put your form ID Here] + "&timezoneOffset=180&minResponseId=1&maxResponseId=1000"

 

The token is automatically generated in the site section. 

 

So, unfortunately, you need to use a browser to use the API. I tried everything to get files using code and nothing worked.

 

If you find out how to generate the token by code, please share it with us! Tks

Sure thing. I am trying to generate the code so I could further process the forms data in an internal workflow. Once I have the full picture will share it with community :)

Looking forward to seeing what you come up with.  Power Automate is often just to picking up that a form was submitted.  So I'm looking at alternatives.  Thanks.

@JimmyStewart 

 

I need a Microsoft Forms API so that I can programmatically create new forms/polls and add them to every Microsoft Teams meeting/invite or click a button during Teams meeting to send form out to all attendees. Each meeting should be able to use a same/similar forms template but generate a new form so that CEO can poll attendees and graph responses. It seems this capability should be here already. Would be nice to be able to generate the form from a forms template on the fly and provide a Microsoft Forms bot to deliver the poll to the user in an interactive format.

@JTAPPS-1exactly what I'm trying to do - programmatically create a microsoft form. After that I can use Logic Apps for example, but the creation of the form is what I'm missing. Simply put I have some variables in powershell that I want to become a microsoft form.

@badsector @JTAPPS-1 +1 to having Microsoft Forms API to be able to programmatically create forms. I've personally found the "branching" feature to not be very intuitive and more importantly error prone for creating more complex forms. I was hoping once I figured out high level details, that I could build the form much faster using automation. Perhaps even PowerShell cmdlets but would be okay with just REST API. This topic was extremely difficult to search for online and had to go through multiple forums to eventually land here which sounds like such an API does not exists :sad:

https://forms.office.com/formapi/api

Having opened https://forms.office.com you can then open the API link in another tab, or you can create an App Reg to call the API. BTW - you can use https://jsonformatter.org/ to copy the raw JSON and see it pretty. Add /forms to the API link to see you forms.

I need to do more work as to the automation opportunities with these APIs (or limitations).
Well when I open https://forms.office.com/formapi/api I get either "{"error":{"code":"711","message":"Required user login. The token is expired."}}" or "{"error":{"code":"701","message":"Required user login."}}". I log in beforehand, but still the same.
It requires an access token which can be issued by first logging into https://forms.office.com. Using a new tab in the same browser session to access the API URL should work then. If assigning to an Azure AD application, you'll find "Microsoft Forms" in the "APIs my organization uses" in the API Permissions panel. If assigning Application API Permissions, it requires Admin consent. When running from the browser, you're running under your user context and will only see the forms you own.

https://forms.office.com (to get access token in browser)

https://forms.office.com/formapi/api/forms (see all forms you own)
https://forms.office.com/formapi/api/forms/{form ID} (see a specific form)
https://forms.office.com/formapi/api/forms/{form ID}/questions (see a specific form's questions)
https://forms.office.com/formapi/api/forms/{form ID}/responses (see a specific form's responses)
This is great, I've just used this to access the form responses for any of my forms. Thanks for sharing!
That looks like an API to get the results from a form. This could be done with Logic Apps. What I'm looking for is a way to create new forms programmatically, e.g. from powershell.

@PJ Johnson This is very helpful and has got me most of the way there, thank you.

 

I have given permissions for an app registration to access the microsoft forms API, with admin consent. I am using the client credential oauth 2 authentication flow to get a bearer token for this app registration to the https://forms.office.com/.default scope. However, when using that token with in the Authorization header of the API call to one of the endpoints listed, it tells me I am not logged in. I have tried using the bearer token scraped off a browser-based API call in it's place, and that works fine. So I know there's nothing wrong with my call, instead, something is wrong with my app registration authentication.

Given the error "701: Required user login", I am starting to think that app registrations just aren't working yet. But then, as you pointed out, the option is there to give Application API permissions in AD?!

 

How did you manage to do this? What am I missing?

@eddierthomas Can you provide some steps including app registration and how you are invoking the API

Hello Binary Botany - did you ever figure this out ?