HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback


Note

Optimizely Forms is only supported by MVC-based websites and HTML5-compliant browsers.

The `Forms.ServiceAPI` has the following attributes:

  • Exposes RESTful API for reading data of a form.

    • If you specify `neededLanguage`, only expose data where `SYSTEMCOLUMN-language="neededLanguage";` you do not need to show the `SYSTEMCOLUMN-language` column.

    • If you do not specify `neededLanguage`, show data for all languages, and also show `SYSTEMCOLUMN-language`.

  • Supports CSV, XML, XLSX, and JSON formats.

  • Supports pagination.

  • Compatible with OData. - [$filter](🔗) defined by OData can be used to filter on `SYSTEMCOLUMN\_SubmitUser and SYSTEMCOLUMN\_FinalizedSubmission`. For example: `http://localhost:56908/EPiServer.Forms.ServiceApi/GetFormData(Id=114,Language=null)?$filter=SYSTEMCOLUMN_SubmitUser`. The `SYSTEMCOLUMN\_SubmitTime` is not compatible with OData serializing. You should use `$filter` without `SYSTEMCOLUMN\_SubmitTime` and filter the data by code.

  • For implementation, writes the extension on top of the ServiceAPI to use its OAuth2 handling.

Note

If you enable **Allow Exposing Data Feeds** in a form container, allowed credentials can fetch data with the ServiceAPI.

675


## Work with the API

`EPiServer.Forms.ServiceApi` is based on `EPiServer.ServiceApi`.

  1. Install the `EPiServer.Forms.ServiceApi` NuGet package with Visual Studio and rebuild the solution.

  2. Update the `EPiServer.ServiceApi` to latest version by running the following command in the Package Manager Console.

    
  3. Update _appsetting.json_ to config `ClientId` and `ClientSecret`

    
  4. Bind HTTPS for your site.

    `EPiServer.Forms.ServiceApi` depends on `EPiServer.ServiceApi`, which requires using https for consuming APIs, so you need go to IIS and bind https for your website.

    621
    
  5. Verify that `EPiServer.Forms.ServiceApi` is working.

    Before you can use the `ServiceApi`, access `https://YourSite//EPiServer.Forms.ServiceApi` from a browser. If it returns JSON like this:

    

    ...then it is working. If it does not return anything, re-install nuget then try again

  6. Grant permission for the Config user to use `ServiceApi`.

    1. Go to the admin view >** Config **>** Security **>** Permissions for Functions**.

    2. Add the user or group to the **EPiServerServiceApi Read Access** right. This user is for authenticating when you consume the `ServiceApi`.

1506

  1. Implement OAuth2 client to access the service.



You can use the OAuth2Client class to access the service to get data. The service exposes three methods:

  • GetFormsInfo. Gets forms in the system. Accept language as parameter; if the language parameter is null, it returns form information in the master language. The requesting user must have read-access with the form to get data.

  • GetFormData. Fetches posted data of a specified form. You need to specify form id and language as parameters; language can be null, which returns data from all languages.

  • GetFieldMapping. Gets mappings between field name and their friendly name. You need to specify form id and form language.

  • DeleteFormData. [New in Forms Service API 3.1.0] Deletes posted data of a specified form. You need to specify form Id and SubmissionIds as parameters.

To invoke `DeleteFormData` action, use a POST request and JSON data format for the parameters in the request body. Example:

The service is compatible with OData 8.0. The following example shows how to use these methods.