Query Forms API to get scores or results from form submission

Copper Contributor

Hello All,

May be one for the Forms/Dev Community but thought I would try here. We have a process where 4 forms are submitted weekly (Every week has 4 new forms). We currently gather responses into a SPO list and feed that in PowerBI.

A new requirement has come in that the forms (which are quizzes) also need to push the scores to SPO. We have done this with conditionals to check the text of the correct answers but the workload for this is unmanageable. I know there is a forms Api (undocumented) and we have successfully queried it to get the quiz questions, but these doesn't seem to be any info in there about the right answer. 

My question is, is it possible to query the forms API to get the response points, either total or per question?

Included is the starting point, just need to know if anyone knows the URI to get what we need.

17 Replies

@jshaunBTC 

 

Use below API to get the form definition which contains the answer and points information per question -

GET https://forms.office.com/formapi/api/{TenantId}/users/{UserId}/light/forms('FormId')?$select=id,order,otherInfo,questions($expand=choices)

 

e.g.,

"questionInfo": "{\"Choices\":[{\"Description\":\"Option 1\",\"IsGenerated\":true,\"IsAnswerKey\":true},{\"Description\":\"Option 2\",\"IsGenerated\":true,\"IsAnswerKey\":false}],\"ChoiceType\":1,\"AllowOtherAnswer\":false,\"OptionDisplayStyle\":\"ListAll\",\"ChoiceRestrictionType\":\"None\",\"ShowRatingLabel\":false,\"Point\":10}",

 

Use below API to get the aggregated results which contains responses and total score -

GET https://forms.office.com/formapi/api/{TenantId}/users/{UserId}/forms('FormId')/GetAggregateQuizData

 

e.g.,

"quizSummaryData": {
"averageScore": 10.0,
"averageSubmitTimeSeconds": 2.0,
"count": 1

Will this work for grabbing the score results when a person submits are response, or will only ever give aggregate results for everyone?
It will aggregate results for everyone, but you can filter by user name (email address) since the results contain that identifying information.
Great thanks, Dingkun Xie, I'll let you know when Ive gone back to it and will mark you as bets response.
Using GetAggregateQuizData uri returns the following failure:

Unexpected response from the service
clientRequestId: 2c821506-a025-4e00-a49e-0ffdeb75bda4

Can I confirm, is the userID in the query params the owner of said form?

@jshaunBTC

 

It depends on the type of form/quiz you created. If it's a personal form, the form owner's user object ID (GUID) will be used, whereas if it's a group form, the group ID will be used. You can obtain the tenant ID and user ID through the network trace when you load the form. For example, in Edge developer mode, open the form and view the network trace sent to forms.office.com. The URLs of the APIs sent to the server will contain the tenant ID and user (group) ID of your form. 

@DingkunXie What is your source for this information?

This is how we implement it in our service.

Any idea on how to access this API using Power Automate? Recently, we've encountered problems with this API; it used to work with Power Automate but has not been functioning for the past week.

 

Connection: Send an HTTP request to SharePoint
{
"status": 401,
"message": "{\"error\":{\"code\":\"701\",\"message\":\"Required user login.\"}}\r\nclientRequestId: xxxxx",
"source": "https://forms.office.com/formapi/DownloadExcelFile.ashx?formid=XXXXXXX",
"errors": []
}

 

We attempted to use the Forms synchronized Excel file from SharePoint, but it only updates with the actual form data when accessed through a browser.

I've had the same problem - working great for ages, then it's suddenly stopped working.
It looks like setting up new SharePoint connection references fixes the problem.
Ah, that's brilliant, such a simple solution - it worked. Many thanks.

@jawadahmed My flow suddenly stopped working, it breaks at the HTTP Get block with the static forms excel link. I re-added the sharpoint connection and it still doesn't work. Does anyone know what changes Microsoft made to break this?

This stopped working again yesterday and setting up new connections hasn't worked this time.

@dfo222 we are also experiencing this issue. It use to work but hasn't worked the past couple weeks. Nothing has changed on our end. 

Creating a new connection reference isn't working anymore.
Yeah, I gave up in the end and have reverted to marking the quiz in the flow. The most efficient method I found for doing that is this one: https://youtu.be/vyWH6Csjof8