diff --git a/certified-connectors/SurveyMonkey/apiDefinition.swagger.json b/certified-connectors/SurveyMonkey/apiDefinition.swagger.json new file mode 100644 index 0000000000..64c1dd12cf --- /dev/null +++ b/certified-connectors/SurveyMonkey/apiDefinition.swagger.json @@ -0,0 +1,1050 @@ +{ + "swagger": "2.0", + "info": { + "x-ms-deployment-version": "1.0.0", + "version": "1.0", + "title": "SurveyMonkey", + "description": "SurveyMonkey is the world's leading provider of web-based survey solutions. These solutions are used by companies, organizations, and individuals to gather the insights they need to make more informed decisions.", + "x-ms-api-annotation": { + "status": "Preview" + }, + "contact": { + "name": "Microsoft", + "url": "https://support.microsoft.com" + } + }, + "host": "api.surveymonkey.net", + "basePath": "/v3", + "schemes": [ + "https" + ], + "paths": { + "/surveys": { + "get": { + "summary": "List surveys", + "description": "List the surveys in the account.", + "operationId": "GetSurveys", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Surveys" + } + } + }, + "deprecated": false, + "x-ms-visibility": "internal" + } + }, + "/collectors/{collectorId}": { + "get": { + "summary": "Get a collector", + "description": "Get details of a specific collector.", + "operationId": "GetSurveyCollector", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [ + { + "name": "collectorId", + "in": "path", + "required": true, + "x-ms-summary": "Collector Id", + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/SurveyCollector" + } + } + }, + "deprecated": false, + "x-ms-visibility": "internal" + } + }, + "/collectors/{collectorId}/messages": { + "get": { + "summary": "Get messages", + "description": "Get survey messages for a given survey collector.", + "operationId": "GetSurveyMessages", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [ + { + "name": "collectorId", + "in": "path", + "required": true, + "x-ms-summary": "Collector Id", + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/SurveyMessages" + } + } + }, + "deprecated": false, + "x-ms-visibility": "internal" + } + }, + "/surveys/{surveyId}/collectors": { + "get": { + "summary": "List collectors", + "description": "Get a list of collectors for a given survey.", + "operationId": "GetSurveyCollectors", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [ + { + "name": "surveyId", + "in": "path", + "description": "Select a survey", + "required": true, + "x-ms-summary": "Survey Id", + "x-ms-dynamic-values": { + "operationId": "GetSurveys", + "value-collection": "data", + "value-path": "id", + "value-title": "title" + }, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/SurveyCollectors" + } + } + }, + "deprecated": false, + "x-ms-visibility": "internal" + } + }, + "/surveys/{surveyId}": { + "get": { + "summary": "Get a survey", + "description": "Get details of a specific survey.", + "operationId": "GetSurvey", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [ + { + "name": "surveyId", + "in": "path", + "required": true, + "x-ms-summary": "Survey Id", + "description": "The id of the survey", + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/Survey" + } + } + }, + "deprecated": false, + "x-ms-visibility": "advanced" + } + }, + "/collectors/{collectorId}/messages/{messageId}/send": { + "post": { + "summary": "Schedule an existing invite message", + "description": "Send or schedule to send an existing message to all message recipients.", + "operationId": "SendMessage", + "consumes": [ + "application/json", + "text/json", + "application/xml", + "text/xml", + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [ + { + "name": "surveyId", + "in": "query", + "description": "Select a survey", + "required": true, + "x-ms-summary": "Survey Id", + "x-ms-dynamic-values": { + "operationId": "GetSurveys", + "value-collection": "data", + "value-path": "id", + "value-title": "title" + }, + "type": "string" + }, + { + "name": "collectorId", + "in": "path", + "description": "Select a collector", + "required": true, + "x-ms-summary": "Collector Id", + "x-ms-dynamic-values": { + "operationId": "GetSurveyCollectors", + "value-collection": "data", + "value-path": "id", + "value-title": "name", + "parameters": { + "surveyId": { + "parameter": "surveyId" + } + } + }, + "type": "string" + }, + { + "name": "messageId", + "in": "path", + "description": "Select a message", + "required": true, + "x-ms-summary": "Message Id", + "x-ms-dynamic-values": { + "operationId": "GetSurveyMessages", + "value-collection": "data", + "value-path": "id", + "value-title": "type", + "parameters": { + "collectorId": { + "parameter": "collectorId" + } + } + }, + "type": "string" + }, + { + "name": "body", + "in": "body", + "required": false, + "schema": { + "type": "object", + "properties": { + "scheduled_date": { + "format": "date-time", + "description": "Time format: yyyy-MM-ddTHH:mm:ss.fffZ (2016-07-20T08:00:00.000Z)", + "type": "string", + "x-ms-summary": "Scheduled date", + "x-ms-visibility": "advanced" + } + } + }, + "x-ms-summary": "Scheduled date" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/SurveyMessageResponse" + } + } + }, + "deprecated": false, + "x-ms-visibility": "important", + "x-ms-no-generic-test": true + } + }, + "/trigger1/surveys": { + "get": { + "summary": "When a new survey is created", + "description": "Triggers a new flow when a survey is created.", + "operationId": "OnSurveyCreated", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/NewSurveys" + } + } + }, + "deprecated": false, + "x-ms-visibility": "important", + "x-ms-trigger": "batch", + "x-ms-trigger-hint": "To see it work now, create a survey." + } + }, + "/trigger2/surveys/{surveyId}/collectors": { + "get": { + "summary": "When a new collector is created", + "description": "Triggers a new flow when a collector is created.", + "operationId": "OnSurveyCollectorCreated", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [ + { + "name": "surveyId", + "in": "path", + "description": "Select a survey", + "required": true, + "x-ms-summary": "Survey Id", + "x-ms-dynamic-values": { + "operationId": "GetSurveys", + "value-collection": "data", + "value-path": "id", + "value-title": "title" + }, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/NewCollectors" + } + } + }, + "deprecated": false, + "x-ms-visibility": "advanced", + "x-ms-trigger": "batch", + "x-ms-trigger-hint": "To see it work now, create a survey collector." + } + }, + "/trigger3/collectors/{collectorId}/responses/bulk": { + "get": { + "summary": "When a new collector response is added", + "description": "Triggers a new flow when a response is added (paid account only).", + "operationId": "OnNewResponseAddedCollector", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [ + { + "name": "surveyId", + "in": "query", + "description": "Select a survey", + "required": true, + "x-ms-summary": "Survey Id", + "x-ms-dynamic-values": { + "operationId": "GetSurveys", + "value-collection": "data", + "value-path": "id", + "value-title": "title" + }, + "type": "string" + }, + { + "name": "collectorId", + "in": "path", + "description": "Select a collector", + "required": true, + "x-ms-summary": "Collector Id", + "x-ms-dynamic-values": { + "operationId": "GetSurveyCollectors", + "value-collection": "data", + "value-path": "id", + "value-title": "name", + "parameters": { + "surveyId": { + "parameter": "surveyId" + } + } + }, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/SurveyResponses" + } + } + }, + "deprecated": false, + "x-ms-visibility": "advanced", + "x-ms-trigger": "batch", + "x-ms-trigger-hint": "To see it work now, respond to a survey." + } + }, + "/trigger4/surveys/{surveyId}/responses/bulk": { + "get": { + "summary": "When a new survey response is added", + "description": "Triggers a new flow when a survey response is added (paid account only).", + "operationId": "OnNewResponseAddedSurvey", + "consumes": [], + "produces": [ + "application/json", + "text/json", + "application/xml", + "text/xml" + ], + "parameters": [ + { + "name": "surveyId", + "in": "path", + "description": "Select a survey", + "required": true, + "x-ms-summary": "Survey Id", + "x-ms-dynamic-values": { + "operationId": "GetSurveys", + "value-collection": "data", + "value-path": "id", + "value-title": "title" + }, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/SurveyResponses" + } + } + }, + "deprecated": false, + "x-ms-visibility": "important", + "x-ms-trigger": "batch", + "x-ms-trigger-hint": "To see it work now, respond to a survey." + } + } + }, + "definitions": { + "Surveys": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "object", + "properties": { + "href": { + "description": "Link to the survey.", + "type": "string", + "x-ms-summary": "Link", + "x-ms-visibility": "advanced" + }, + "id": { + "description": "The survey identifier.", + "type": "string", + "x-ms-summary": "Survey Id", + "x-ms-visibility": "advanced" + }, + "title": { + "description": "The title of the survey.", + "type": "string", + "x-ms-summary": "Title", + "x-ms-visibility": "important" + } + } + } + } + } + }, + "SurveyCollectors": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "object", + "properties": { + "href": { + "description": "Link to collector.", + "type": "string", + "x-ms-summary": "Link", + "x-ms-visibility": "advanced" + }, + "name": { + "description": "The name of the collector.", + "type": "string", + "x-ms-summary": "Name", + "x-ms-visibility": "important" + }, + "id": { + "description": "The collector identifier.", + "type": "string", + "x-ms-summary": "Collector Id", + "x-ms-visibility": "advanced" + } + } + } + } + } + }, + "SurveyCollector": { + "type": "object", + "properties": { + "status": { + "description": "The status of the survey.", + "type": "string", + "x-ms-summary": "Status", + "x-ms-visibility": "important" + }, + "redirect_url": { + "description": "Redirect to this url upon survey completion.", + "type": "string", + "x-ms-summary": "Survey Redirect Url", + "x-ms-visibility": "advanced" + }, + "thank_you_message": { + "description": "Message for thank you page.", + "type": "string", + "x-ms-summary": "Thank You Message", + "x-ms-visibility": "advanced" + }, + "response_count": { + "format": "int32", + "description": "The number of survey responses.", + "type": "integer", + "x-ms-summary": "Response Count", + "x-ms-visibility": "important" + }, + "closed_page_message": { + "description": "Message shown when a survey is closed.", + "type": "string", + "x-ms-summary": "Closed Message", + "x-ms-visibility": "advanced" + }, + "href": { + "description": "Link to the survey collector.", + "type": "string", + "x-ms-summary": "Link", + "x-ms-visibility": "advanced" + }, + "close_date": { + "description": "Close date of collector.", + "type": "string", + "x-ms-summary": "Close Date", + "x-ms-visibility": "advanced" + }, + "id": { + "description": "The collector identifier.", + "type": "string", + "x-ms-summary": "Collector Id", + "x-ms-visibility": "advanced" + }, + "name": { + "description": "The name of the collector.", + "type": "string", + "x-ms-summary": "Name", + "x-ms-visibility": "important" + }, + "date_modified": { + "format": "date-time", + "description": "The date the collector was last modified.", + "type": "string", + "x-ms-summary": "Modified Date", + "x-ms-visibility": "advanced" + }, + "edit_response_type": { + "description": "Type of response.", + "type": "string", + "x-ms-summary": "Response Type", + "x-ms-visibility": "advanced" + }, + "sender_email": { + "description": "Collector sender email.", + "type": "string", + "x-ms-summary": "Sender Email", + "x-ms-visibility": "advanced" + }, + "date_created": { + "format": "date-time", + "description": "The date the collector was created.", + "type": "string", + "x-ms-summary": "Created Date", + "x-ms-visibility": "advanced" + }, + "disqualification_message": { + "description": "Message for disqualification page.", + "type": "string", + "x-ms-summary": "Disqualification Date", + "x-ms-visibility": "advanced" + }, + "type": { + "description": "Collector type: 'weblink’ or 'email’.", + "type": "string", + "x-ms-summary": "Collector Type", + "x-ms-visibility": "advanced" + } + } + }, + "Survey": { + "type": "object", + "properties": { + "response_count": { + "format": "int32", + "description": "Number of responses survey has received.", + "type": "integer", + "x-ms-summary": "Response Count", + "x-ms-visibility": "important" + }, + "page_count": { + "format": "int32", + "description": "Number of pages in the survey.", + "type": "integer", + "x-ms-summary": "Page Count", + "x-ms-visibility": "advanced" + }, + "id": { + "description": "The survey identifier.", + "type": "string", + "x-ms-summary": "Survey Id", + "x-ms-visibility": "advanced" + }, + "question_count": { + "format": "int32", + "description": "Number of questions in survey.", + "type": "integer", + "x-ms-summary": "Question Count", + "x-ms-visibility": "advanced" + }, + "category": { + "description": "Survey category chosen when creating the survey.", + "type": "string", + "x-ms-summary": "Survey Category", + "x-ms-visibility": "advanced" + }, + "preview": { + "description": "Survey preview URL.", + "type": "string", + "x-ms-summary": "Preview Url", + "x-ms-visibility": "advanced" + }, + "language": { + "description": "Survey language.", + "type": "string", + "x-ms-summary": "Language", + "x-ms-visibility": "advanced" + }, + "date_modified": { + "format": "date-time", + "description": "The date the survey was last modified.", + "type": "string", + "x-ms-summary": "Modified Date", + "x-ms-visibility": "advanced" + }, + "title": { + "description": "The title of the survey.", + "type": "string", + "x-ms-summary": "Title", + "x-ms-visibility": "important" + }, + "analyze_url": { + "description": "The URL for the results of the survey.", + "type": "string", + "x-ms-summary": "Analyze Url", + "x-ms-visibility": "important" + }, + "summary_url": { + "description": "The URL for the summary of the survey.", + "type": "string", + "x-ms-summary": "Summary Url", + "x-ms-visibility": "important" + }, + "date_created": { + "format": "date-time", + "description": "The date the survey was created.", + "type": "string", + "x-ms-summary": "Created Date", + "x-ms-visibility": "advanced" + }, + "collect_url": { + "description": "Survey collect URL.", + "type": "string", + "x-ms-summary": "Collect Url", + "x-ms-visibility": "advanced" + }, + "edit_url": { + "description": "Survey edit URL.", + "type": "string", + "x-ms-summary": "Edit Url", + "x-ms-visibility": "advanced" + } + } + }, + "SurveyMessages": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "object", + "properties": { + "status": { + "description": "The status of the message.", + "type": "string", + "x-ms-summary": "Message status", + "x-ms-visibility": "important" + }, + "href": { + "description": "Link to message.", + "type": "string", + "x-ms-summary": "Link", + "x-ms-visibility": "important" + }, + "type": { + "description": "Type of message.", + "type": "string", + "x-ms-summary": "Type", + "x-ms-visibility": "advanced" + }, + "id": { + "description": "The message identifier.", + "type": "string", + "x-ms-summary": "Message Id", + "x-ms-visibility": "advanced" + } + } + } + } + } + }, + "SurveyMessageResponse": { + "type": "object", + "properties": { + "is_scheduled": { + "description": "Link to message results.", + "type": "string", + "x-ms-summary": "Link", + "x-ms-visibility": "advanced" + }, + "scheduled_date": { + "format": "date-time", + "description": "Date message was scheduled to be sent.", + "type": "string", + "x-ms-summary": "Scheduled Date", + "x-ms-visibility": "advanced" + }, + "body": { + "description": "The plain text body of the email message to be sent to recipients.", + "type": "string", + "x-ms-summary": "Message Body", + "x-ms-visibility": "important" + }, + "subject": { + "description": "Subject of the email message to be sent to recipients.", + "type": "string", + "x-ms-summary": "Subject", + "x-ms-visibility": "important" + }, + "recipients": { + "description": "List of recipient ids.", + "type": "array", + "items": { + "type": "string" + }, + "x-ms-summary": "Recipients", + "x-ms-visibility": "advanced" + }, + "recipient_status": { + "description": "The recipient status.", + "type": "string", + "x-ms-summary": "States", + "x-ms-visibility": "advanced" + }, + "type": { + "type": "string", + "x-ms-visibility": "advanced" + } + } + }, + "NewSurveys": { + "type": "array", + "items": { + "type": "object", + "properties": { + "href": { + "description": "Link to the survey.", + "type": "string", + "x-ms-summary": "Link", + "x-ms-visibility": "advanced" + }, + "id": { + "description": "The survey identifier.", + "type": "string", + "x-ms-summary": "Survey Id", + "x-ms-visibility": "important" + }, + "title": { + "description": "The title of the survey.", + "type": "string", + "x-ms-summary": "Title", + "x-ms-visibility": "important" + } + } + } + }, + "NewCollectors": { + "type": "array", + "items": { + "type": "object", + "properties": { + "href": { + "description": "Link to survey collector.", + "type": "string", + "x-ms-summary": "Link", + "x-ms-visibility": "advanced" + }, + "id": { + "description": "The collector identifier.", + "type": "string", + "x-ms-summary": "Collector Id", + "x-ms-visibility": "advanced" + }, + "name": { + "description": "The name of the collector.", + "type": "string", + "x-ms-summary": "Name", + "x-ms-visibility": "important" + } + } + } + }, + "SurveyResponses": { + "type": "array", + "items": { + "type": "object", + "properties": { + "total_time": { + "format": "int32", + "description": "Total time spent on the response.", + "type": "integer", + "x-ms-summary": "Time Spent", + "x-ms-visibility": "advanced" + }, + "href": { + "description": "Survey response link.", + "type": "string", + "x-ms-summary": "Link", + "x-ms-visibility": "important" + }, + "ip_address": { + "description": "IP address of responder.", + "type": "string", + "x-ms-summary": "IP Address", + "x-ms-visibility": "advanced" + }, + "id": { + "description": "The response identifier.", + "type": "string", + "x-ms-summary": "Response Id", + "x-ms-visibility": "advanced" + }, + "date_modified": { + "format": "date-time", + "description": "The date the response was last modified.", + "type": "string", + "x-ms-summary": "Modified Date", + "x-ms-visibility": "advanced" + }, + "response_status": { + "description": "Status of the response.", + "type": "string", + "x-ms-summary": "Response Status", + "x-ms-visibility": "advanced" + }, + "custom_value": { + "description": "Custom value associated with a response.", + "type": "string", + "x-ms-summary": "Custom Value", + "x-ms-visibility": "advanced" + }, + "analyze_url": { + "description": "Link to the analyze page to view the response.", + "type": "string", + "x-ms-summary": "Analyze Url", + "x-ms-visibility": "important" + }, + "recipient_id": { + "description": "The recipient identifier.", + "type": "string", + "x-ms-summary": "Recipient Id", + "x-ms-visibility": "advanced" + }, + "collector_id": { + "description": "The collector identifier.", + "type": "string", + "x-ms-summary": "Collector Id", + "x-ms-visibility": "advanced" + }, + "date_created": { + "format": "date-time", + "description": "The date the response was created.", + "type": "string", + "x-ms-summary": "Created Date", + "x-ms-visibility": "important" + }, + "survey_id": { + "description": "The survey identifier.", + "type": "string", + "x-ms-summary": "Survey Id", + "x-ms-visibility": "advanced" + }, + "collection_mode": { + "description": "Response collection mode.", + "type": "string", + "x-ms-summary": "Collection Mode", + "x-ms-visibility": "advanced" + }, + "first_name": { + "type": "string", + "description": "First name of the recepient.", + "x-ms-summary": "First Name", + "x-ms-visibility": "advanced" + }, + "last_name": { + "type": "string", + "description": "Last name of the recepient.", + "x-ms-summary": "Last Name", + "x-ms-visibility": "advanced" + }, + "email_address": { + "type": "string", + "description": "Email Address of the recepient.", + "x-ms-summary": "Email Address", + "x-ms-visibility": "advanced" + }, + "logic_path": { + "type": "object", + "properties": {}, + "description": "Logic path taken during the survey." + }, + "metadata": { + "type": "object", + "properties": { + "contact": { + "type": "object", + "properties": {}, + "description": "contact" + } + }, + "description": "Other associated metadata or custom values." + }, + "page_path": { + "type": "array", + "items": {}, + "description": "The order in which the pages were responded to." + }, + "pages": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "id" + }, + "questions": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "id" + }, + "answers": { + "type": "array", + "items": { + "type": "object", + "properties": { + "choice_id": { + "type": "string", + "description": "Choice Id" + } + } + }, + "description": "answers" + } + } + }, + "description": "questions" + } + } + }, + "description": "Pages from the survey and their associated responses." + }, + "edit_url": { + "description": "Link to the survey page to edit the response.", + "type": "string", + "x-ms-summary": "Edit Url", + "x-ms-visibility": "advanced" + } + }, + "x-ms-visibility": "advanced" + } + } + }, + "x-ms-capabilities": { + "testConnection": { + "operationId": "GetSurveys" + } + }, + "x-ms-connector-metadata": [ + { + "propertyName": "Website", + "propertyValue": "https://www.surveymonkey.com/" + }, + { + "propertyName": "Privacy policy", + "propertyValue": "https://www.surveymonkey.com/mp/legal/privacy-policy/" + }, + { + "propertyName": "Categories", + "propertyValue": "Content and Files;Productivity" + } + ] +} \ No newline at end of file diff --git a/certified-connectors/SurveyMonkey/apiProperties.json b/certified-connectors/SurveyMonkey/apiProperties.json new file mode 100644 index 0000000000..508cd1c724 --- /dev/null +++ b/certified-connectors/SurveyMonkey/apiProperties.json @@ -0,0 +1,58 @@ +{ + "properties": { + "connectionParameters": { + "token": { + "type": "oauthSetting", + "oAuthSettings": { + "identityProvider": "oauth2generic", + "scopes": [ + "View Surveys", + "View Collectors", + "View Responses", + "View Response Details" + ], + "clientId": "<>", + "redirectMode": "direct", + "customParameters": { + "AuthorizationUrlTemplate": { + "value": "https://api.surveymonkey.net/oauth/authorize" + }, + "AuthorizationUrlQueryStringTemplate": { + "value": "?client_id={ClientId}&response_type=code&redirect_uri={RedirectUrl}&state={state}" + }, + "TokenUrlTemplate": { + "value": "https://api.surveymonkey.net/oauth/token" + }, + "TokenUrlQueryStringTemplate": { + "value": "" + }, + "RefreshUrlTemplate": { + "value": null + }, + "RefreshBodyTemplate": { + "value": null + }, + "ScopeListDelimiter": { + "value": " " + } + } + }, + "uiDefinition": { + "displayName": "Log in with your credentials", + "description": "Log in with your credentials", + "tooltip": "Log in with your credentials", + "constraints": { + "required": "true" + } + } + } + }, + "iconBrandColor": "#00BF6F", + "capabilities": [ + "actions", + "triggers" + ], + "publisher": "Microsoft", + "stackOwner": "Microsoft" + } +} \ No newline at end of file diff --git a/certified-connectors/SurveyMonkey/readme.md b/certified-connectors/SurveyMonkey/readme.md new file mode 100644 index 0000000000..c6f1aa5221 --- /dev/null +++ b/certified-connectors/SurveyMonkey/readme.md @@ -0,0 +1,36 @@ +# SurveyMonkey +SurveyMonkey is the world's leading provider of web-based survey solutions. These solutions are used by companies, organizations, and individuals to gather the insights they need to make more informed decisions. + +## Prerequisites +To use this integration, you will need a SurveyMonkey account. + +## Publisher: Microsoft + +## Obtaining Credentials +A SurveyMonkey account (trial or paid) is needed to register an application. You can start a trial [here](https://www.surveymonkey.com/). After that you can go to the [developer page](https://developer.surveymonkey.com/api/v3/#registering-an-app) and register your application there. From there you can grab the app key and secret. + +## Supported Operations +#### Get a survey +Get details of a specific survey. + +#### Schedule an existing invite message +Send or schedule to send an existing message to all message recipients. + +#### When a new collector response is added +Triggers a new flow when a response is added (paid account only). + +#### When a new survey response is added +Triggers a new flow when a survey response is added (paid account only). + +#### When a new survey is created +Triggers a new flow when a survey is created. + +#### When a new collector is created +Triggers a new flow when a collector is created. + + +## Known issues and limitations +The connector is based on integration with [surveymonkey.com](https://www.surveymonkey.com/) portal accounts. Other region-specific instances are not supported. + +## Deployment instructions +Please use [these instructions](https://docs.microsoft.com/en-us/connectors/custom-connectors/paconn-cli) to deploy this connector as custom connector in Microsoft Power Automate and Power Apps \ No newline at end of file diff --git a/certified-connectors/SurveyMonkey/script.csx b/certified-connectors/SurveyMonkey/script.csx new file mode 100644 index 0000000000..8c5282b309 --- /dev/null +++ b/certified-connectors/SurveyMonkey/script.csx @@ -0,0 +1,226 @@ +public class Script : ScriptBase +{ + public override async Task ExecuteAsync() + { + var check = await this.UpdateRequest().ConfigureAwait(false); + if (check == false) + { + var triggerResponse = new HttpResponseMessage(HttpStatusCode.Accepted); + triggerResponse.Headers.Location = SetLocationHeader(string.Empty, string.Empty); + return triggerResponse; + } + var response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(false); + if (response.IsSuccessStatusCode) + { + await this.UpdateResponse(response).ConfigureAwait(false); + } + return response; + } + + private Uri SetLocationHeader(string triggerState, string excludeIds) + { + var locationUriBuilder = new UriBuilder(this.Context.OriginalRequestUri); + var query = HttpUtility.ParseQueryString(this.Context.OriginalRequestUri.Query); + string newTriggerState = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); + if (!String.IsNullOrEmpty(triggerState)) + { + newTriggerState = triggerState; + } + query["triggerstate"] = newTriggerState; + query["triggerstate_exclude_ids"] = excludeIds; + locationUriBuilder.Query = query.ToString(); + return locationUriBuilder.Uri; + } + + private string SetBody(string content) + { + string body = string.Empty; + if (!String.IsNullOrEmpty(content)) + { + JObject modifiedRequestBody = null; + JObject requestBody = JObject.Parse(content); + + switch (this.Context.OperationId.ToLower()) + { + case "sendmessage": + if (requestBody["scheduled_date"] != null) + { + string scheduled_date = (string)requestBody["scheduled_date"]; + if (!string.IsNullOrWhiteSpace(scheduled_date)) + { + modifiedRequestBody = JObject.Parse("{ 'scheduled_date' : '" + scheduled_date + "' }"); + } + } + break; + + default: + return body; + } + body = (modifiedRequestBody == null) ? "{}" : modifiedRequestBody.ToString(); + } + else + { + switch (this.Context.OperationId.ToLower()) + { + case "sendmessage": + body = "{}"; + break; + } + } + return body; + } + + public JArray GetNewItems(JArray items) + { + var originalQuery = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query); + var triggerState = originalQuery.Get("triggerstate"); + if (items != null && triggerState != null) + { + var listOfOperations = new List() { "OnNewResponseAddedCollector", "OnNewResponseAddedSurvey" }; + + if (listOfOperations.Contains(this.Context.OperationId, StringComparer.OrdinalIgnoreCase)) + { + string serializedExcludeIds = string.Empty; + var triggerStateExcludes = originalQuery.Get("triggerstate_exclude_ids"); + if (triggerStateExcludes != null) + { + serializedExcludeIds = triggerStateExcludes; + } + if (serializedExcludeIds != string.Empty) + { + var excludeIds = new HashSet(serializedExcludeIds.Split(new char[] { ',' })); + items = new JArray(items.Where(x => !excludeIds.Contains(x["id"].ToString()))); + } + items = (items?.Count > 0 ? items : new JArray()); + } + } + return items; + } + + public string SetTriggerState(JArray newItems, string triggerState, string date) + { + DateTime newTriggerState = DateTime.MinValue; + string excludeIds = string.Empty; + var listOfOperations = new List() { "OnNewResponseAddedCollector", "OnNewResponseAddedSurvey" }; + + if (listOfOperations.Contains(this.Context.OperationId, StringComparer.OrdinalIgnoreCase) && newItems != null) + { + if (newItems.Count > 0) + { + newTriggerState = newItems.Max(x => DateTime.Parse(x["date_modified"].ToString())); + newTriggerState = newTriggerState.AddSeconds(1); + /* now get the ids of any responses with modified date in the same minute as the next trigger date so we can exclude them from the next run */ + excludeIds = string.Join(",", newItems.Where(x => DateTime.Parse(x["date_modified"].ToString()).ToString("yyyy-MM-ddTHH:mmZ") == newTriggerState.ToString("yyyy-MM-ddTHH:mmZ")).Select(y => y["id"].ToString())); + } + } + + if ((newItems == null || newItems.Count == 0) && !String.IsNullOrEmpty(triggerState) && newTriggerState == DateTime.MinValue) + { + newTriggerState = DateTime.Parse(triggerState); + } + else if (newTriggerState == DateTime.MinValue) + { + newTriggerState = DateTime.Parse(date); + } + + return newTriggerState.ToString("yyyy-MM-ddTHH:mm:ss.fffZ") + "|" + excludeIds; + } + + private async Task UpdateRequest() + { + var uriBuilder = new UriBuilder(this.Context.Request.RequestUri); + var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query); + string triggerState = query.Get("triggerstate"); + if (!string.IsNullOrEmpty(triggerState)) + { + // initial trigger state to get existing items + triggerState = DateTime.Parse(triggerState).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); + } + + if ("OnSurveyCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnNewResponseAddedCollector".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnNewResponseAddedSurvey".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnSurveyCollectorCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase)) + { + var segments = this.Context.Request.RequestUri.Segments.ToList(); + var removeTrigger = segments.Find(x => x.StartsWith("trigger")); + uriBuilder.Path = uriBuilder.Path.Replace(removeTrigger, string.Empty); + if (!string.IsNullOrEmpty(triggerState)) + { + if ("OnSurveyCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnNewResponseAddedCollector".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnNewResponseAddedSurvey".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase)) + { + query["start_modified_at"] = triggerState; + } + else if ("OnSurveyCollectorCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase)) + { + query["start_date"] = triggerState; + } + else + { + query["since"] = triggerState; + } + } + else + { + return false; + } + query.Remove("triggerstate"); + query.Remove("triggerstate_exclude_ids"); + } + else + { + var content = await this.Context.Request.Content.ReadAsStringAsync().ConfigureAwait(false); + string body = SetBody(content); + this.Context.Request.Content = new StringContent(body, Encoding.UTF8, "application/json"); + } + query.Remove("surveyId"); + uriBuilder.Query = query.ToString(); + this.Context.Request.RequestUri = uriBuilder.Uri; + + return true; + } + + private async Task UpdateResponse(HttpResponseMessage response) + { + var query = HttpUtility.ParseQueryString(this.Context.OriginalRequestUri.Query); + var triggerState = query.Get("triggerstate"); + if (!String.IsNullOrEmpty(triggerState)) + { + triggerState = DateTime.Parse(triggerState).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); + } + var excludeIds = string.Empty; + + if ("OnSurveyCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnNewResponseAddedCollector".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnNewResponseAddedSurvey".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnSurveyCollectorCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase)) + { + response.Headers.RetryAfter = new RetryConditionHeaderValue(TimeSpan.FromSeconds(60)); + var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var body = JObject.Parse(content); + var newItems = body.SelectToken("data") as JArray; + + if ("OnNewResponseAddedCollector".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) || + "OnNewResponseAddedSurvey".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase)) + { + newItems = GetNewItems(newItems); + var triggerStates = SetTriggerState(newItems, triggerState, response.Headers?.Date.ToString()); + triggerState = triggerStates.Split('|')[0]; + excludeIds = triggerStates.Split('|')[1]; + } + if (newItems != null && newItems.HasValues) + { + response.Content = new StringContent(newItems.ToString(), Encoding.UTF8, "application/json"); + response.StatusCode = HttpStatusCode.OK; + } + else + { + response.Content = null; + response.StatusCode = HttpStatusCode.Accepted; + } + response.Headers.Location = SetLocationHeader(triggerState, excludeIds); + } + } +} \ No newline at end of file