Forum Discussion
ravipokala
Jun 15, 2020Copper Contributor
API to access MS forms
Looking for an API to access MS forms and pull the survey results on a weekly basis.
BinaryBotany
Jun 16, 2022Copper Contributor
This is my set up (set up from scratch to test it), hopefully it can help narrow down the problem:
- Set up a basic App registration (single tenant, no redirect URI).
- Copy the application (client) ID
- Set up a secret. Copy the secret.
- NO API PERMISSIONS REQUIRED (as of writing this). This is strange, but for some reason, it works (for now)
- log into forms through your browser, then open a new tab and go to the following: https://forms.office.com/formapi/api/userInfo
- Grab the (user) id from that response, and use it in the following: https://forms.office.com/formapi/api/{Tenant_id}/users/{User_id}/forms
- Grab a (form) id from that response and now try the following: https://forms.office.com/formapi/api/{Tenant_id}/users/{User_id}/forms
Testing in postman, authenticate using the following and copy the token:
POST to "https://login.microsoftonline.com/{TenantID}/oauth2/v2.0/token"
Body:
- grant_type = client_credentials
- client_id = {app_id copied}
- client_secret = {app_secret copied}
- scope = https://forms.office.com/.default
- (@mpheasent used this with success as well: api://forms.office.com/c9a559d2-7aab-4f13-a6ed-e7e9c52aec87/.default)
9. Replicate the responses call with postman (note the URL encoding of (''):
GET "https://forms.office.com/formapi/api/{Tenant_id}/users/{user_id}/forms%28%27{Form_id}%27%29/responses"
Headers:
- Authorization = Bearer {token}
Haven't figured out a single call to to get all forms for all users yet either. Hope this helps someone nonetheless.
amitkumar4
Feb 09, 2024Copper Contributor
BinaryBotany Is this really working? I am using same setup and it doesn't work
{
"error": "invalid_resource",
"error_description": "AADSTS500011: The resource principal named api://forms.office.com/<tenat> was not found in the tenant named <####>. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant. Trace ID: 4b98a3c5-3a61-452d-82c8-3dcae3f62b00 Correlation ID: c40cdd68-0718-47b0-9227-80b7b0553c3f Timestamp: 2024-02-09 18:56:00Z",
"error_codes": [
500011
],
"timestamp": "2024-02-09 18:56:00Z",
"trace_id": "4b98a3c5-3a61-452d-82c8-3dcae3f62b00",
"correlation_id": "c40cdd68-0718-47b0-9227-80b7b0553c3f",
"error_uri": "https://login.microsoftonline.com/error?code=500011"
}