REST

While Nintex Apps's pre-configured connection types allow you to easily connect to a variety of systems, the REST data source type (DST) allows advanced builders to connect to almost any REST API. REST is web service architecture that typically uses the HTTP protocol, identifies resources with a URL, and represents actions with HTTP methods, also called verbs, such as GET, POST, PUT, DELETE.

Nintex Apps extends the capability to a wide range of REST services, but REST standards such as Swagger can be very helpful in creating services that are easy to use and understand.

Concepts and prerequisites

While the REST data source type is one of the most versatile, it is also one of the most complex. To utilize it fully, you need to have at least a basic-to-moderate understanding of the following concepts:

You'll also need to be familiar with the following for your external system of choice:

  • The individual endpoints for each type of operation and their expected HTTP method
  • The expected request format (headers vs URL parameters vs request payloads)
  • The expected response format
  • Your chosen authentication method (OAuth, basic authentication, etc.)

Configuration

To begin creating a new connection, click Connections > Create.

  1. Select REST from the Connector drop-down.
  2. Give your connection a unique Name.
  3. Click Next.

Configure connection, authentication, URL parameters, and request headers

  • URL / Endpoint: This is the base URL of the connection. For REST services, this will be the first part of the URL, which should be the same for all endpoints in models pointed to this connection.

    As with the example above, this value will look similar to http://www.example.com/api/v1/ for most REST connections.

  • Use proxy: Choose whether or not to use a proxy. By default, this option is selected. See here for more information on the implications of using a proxy.

  • Authentication method: Configure the appropriate authentication settings for this particular connection. Click here for more information about authentication in Nintex Apps.

  • URL parameters & request headers: The request URL will append these parameters to each connection URL for each request. This is typically used for API keys and access tokens.

Using a REST connection

While REST models function very similarly to other DST models at runtime, configuring them properly requires an understanding of some unique concepts covered below.

Model Concepts

Methods

A REST model's methods determine how the model can interact with the data it retrieves from the external system:

  • Query Method: Used to retrieve records
  • Insert Method: Used to create records
  • Update Method: Used to update existing records
  • Delete Method: Used to delete existing records

Some of these model methods can use different HTTP verbs for their operations. For example, query model methods may use GET or POST, while update model methods can use PUT, PATCH, or POST. Use your external system's API documentation to determine which verb to select for each model method.

Connection URLs

Connection URLs are appended to the base URL within the connection's configuration screen.

So a connection with a base URL of https://www.example.com/api/2/ may have connection URLs like the following:

  • contacts/
  • accounts/
  • opportunities/

The base URL ( https://www.example.com/api/2/ in the example above) should be consistent for all of the API's endpoints and is configured in the connection. This base URL can vary in length from service to service, but typically includes the protocol ( https:// in the example above), domain name (www.example.com/), and a URL path to related to the API being accessed (api/2)

The last portion of the URL will be configured at the model-level, for each individual method. Nintex Apps automatically concatenates these two values to form a full URL, so there is no need to input the base URL from the data within each method's connection URL.

Within these connection URLs, you may indicate sections of the URL as merge parameters using curly brackets. This will allow the creation of conditions, used to update the value of those URL merge parameters. Connection URLs are also compatible with global merge variables.

For example, the external system may expect the user to provide an account ID as part of the URL. To create a model supporting that behavior, your connection URL may look like: accounts/{{id}} .

Conditions

Conditions are run when a model is queried and injects values into the connection URL.

Parameter conditions

  1. Add a URL merge parameter to your model’s methods. These parameters are written in the model's Connection URLs .

  2. Below the model, click Conditions.

  3. Click Parameter conditions.

  4. Click Add condition.

  5. Select the URL merge parameter you added in step 1.

  6. Select the condition value.

  7. Select the Condition state.

  8. Click Apply.

Client-side conditions

You can also add a client-side condition based on parameters or other criteria. These conditions are run only against the data that’s already been queried and exists on the page.

  1. Below the model, click Conditions.

  2. Click Client-side conditions.

  3. Click Add condition.

  4. Enter the condition.

  5. Select the Condition state.

  6. Click Apply.

Response formats

JSON and XML are two of the most common formats for receiving responses, but their structure varies significantly. Look at the following examples:

JSON

Copy
{
  "account": {
    "accountId": "8629c7899fa670c61126eee45b6d8826",
    "accountName": "Primary Account",
  }
}

XML

Copy
<account>
  <accountId>8629c7899fa670c61126eee45b6d8826</accountId>
  <accountName>Primary Account</accountName>
</account>

Both responses convey the same data, but their structure is very different. And note that, for XML-based APIs, even their structure may vary from the example listed above.

In general, Nintex Apps has greater support for JSON-based responses, but XML APIs are also supported.

Because of the structure of XML, it's possible to have attributes on a node in addition to its content. These attributes can be accessed when adding fields to the model by clicking the $ object when adding fields to the model.

So if a connection returned a response like this:

Copy
<account type="Partner">
  <accountId>8629c7899fa670c61126eee45b6d8826</accountId>
  <accountName>Primary Account</accountName>
</account>

You could access the type attribute by adding account > $ > type within the model's Fields sub-tab.

Important:  Depending on the structure of some XML-based APIs, Nintex Apps may not be able to interpret their responses correctly. Verify the structure of the API's responses. If problems persist, consider using a snippet to intercept and translate the payload.

Note:  When working with XML-based APIs, you may need to use custom payload templates, or (in some cases) snippets to interface with your chosen API.

Custom requests / payloads

All data sources function through HTTP requests and responses. Other DSTs abstract the logic of those responses and requests, but it is critical to be familiar with your service's expected request/response format when using the REST DST. And while Nintex Apps's basic request options can work with a variety of systems, you may need to alter the way Nintex Apps sends or receives data.

To do so, utilize the REST model's templated requests, payload generation snippets, or payload intercept snippets. To visualize where and how these options affect requests, see the chart below:

rest-0

Request bodies

Every REST API is different, and sometimes services expect requests for certain operations to be formatted in particular ways. To facilitate the variety of ways different external systems may expect to receive data, several methods have a different options for formatting how data is sent. Several methods listed below may have these request body options available.

  • As JSON in request body: Nintex Apps sends the updated fields as JSON in the request payload. For example, a complete payload could look like this:

    Copy
    {"a-field": "This is the new value of the field.","another-field": "Also a new value."}
  • As nested JSON in request body: Nintex Apps nests the updated fields object within a key specified in the Location of nested changes property. For example, a complete payload, nested in data , could look like this:

    Copy
    {"data": {"a-field": "This is the new value of the field.","another-field": "Also a new value."}}
  • As URL-encoded Form data in request body: Nintex Apps sends the updated fields—separated by ampersands (&)—as URL-encoded form data. These requests have a MIME type of application/x-www-form-urlencoded.

    Mainly used for APIs that expect form elements and POST requests. For example, a complete payload may look like this

    a-field=This+is+the+new+value+of+the+field.&another-field=Also+a+new+value.

  • In request headers - one per changed field: of sending values within a payload, Nintex Apps sends updated fields as additional HTTP headers for the request.

    So, in addition to standard request headers (like Content-Type and Origin), Nintex Apps sends additional request headers on the request:

    Copy
    Content-Type: application/JSON Origin: https://example.nintex.app a-field: This is the new value of the field. another-field: Also a new value.
    • Field name to header name mapping: Determines how field names are formatted for HTTP request headers.
      • Same names: If selected, headers will be labeled with their field names as selected from the model's metadata.
      • Same names, with added prefix: If selected, parameters will prefixed with the value in the Headerult name prefix property.
  • In URL parameters - one per changed field: Updated field values are appended as percent-encoded parameters at the end of the method's connection URL.

    As an example:

    A connection whose API endpoint: https://example.com/api/

    On a model with an update method pointing to 2/records/{{id}}

    Updating a record would result in a request to this endpoint URL:

    https://example.com/api/2/records/{{id}}?a-field=This%20is%20a%20new%20value%20of%20the%20field.&another-field=Also%20a%20new%20value

    • Field name to parameter name mapping: Determines how field names are formatted for URL parameters.
      • Same names: If selected, parameters will be appended to the connection URL with their field names as selected from the model's metadata.
      • Same names, with added prefix: If selected, parameters will prefixed with the value in the Parameter name prefix property.
  • As custom payload format in request body: Sends whatever payload is returned by the selected payload generation snippet. Updated values are passed into the snippet as argument[0].changes. For more information, see the payload generation snippet section.

  • As templated request body: Sends the payload as written in the Custom Request field that appears when this option is selected. Compatible with merge syntax. For more information, see the merge template custom payload section.

Sending custom requests

Requests can be customized for methods that use PUT, POST, PATCH, and DELETE HTTP verbs. As of Nintex Apps release 12, this means query and delete methods may also utilize these custom payloads if they have the appropriate HTTP verb.

Note:  If a custom payload is used, or if the response is intercepted by a snippet, Nintex Apps will not attempt to query a model's object for metadata. , you must manually add any fields. Ensure you are familiar with the payload response your external system will send. This also means you will not be able to use Path to Contents option. If receiving a response where you must use Path To Contents, consider using an Intercept Respond Snippet to transform the response so that it has all data on the same object level.

Intercepting response payloads

Some external systems may return payloads in a format that Nintex Apps cannot parse. If network requests are succeeding and returning responses, but Nintex Apps components are not utilizing the data properly, you may need to intercept and alter the response.

As with other Nintex Apps snippets, utilize parameters passed in through arguments[0]. For snippets that intercept responses these include:

  • response : The full response returned by the external system with several nested fields:

    • body : The full response body returned by the external system

    Note:  Whether or not this is a JSON object or XML document depends on the API being accessed.

As with payload generation snippets, Nintex Apps expects these snippets to return data in a JSON object that Nintex Apps recognizes. Nintex Apps expects that each model field will be a separate key in the returned object. If the method has a Path to Contents value, then the fields must be nested within that key as well. Unless data is returned, the model's data will be unusable by Nintex Apps components.

Models properties

In addition to several standard model properties, REST models have some unique properties as well:

  • Model behavior: Determines whether a model will be used for exclusively for querying data, or for querying and updating data.
    • Read-only: Designates that the model can only query. Since only one method will be available, the query method's properties will be listed on the model itself.
    • Read/Write: Designates that the model may use multiple connection URLs for different data operations.
  • Model label and Model plural label: The labels used to represent object being accessed by the model, since that metadata may not be available. These labels can be seen in Nintex Apps's component text, such as Add new < Model label> or Show 10 <Model plural label> Per page.

Method properties

Troubleshooting