How to use App Connect with HTTP

The Hypertext Transfer Protocol (HTTP) is a request/response network protocol that enables clients and servers to communicate. A client typically submits HTTP requests to a server that hosts a service; for example, a server that provides a resource such as an API with a publicly exposed HTTP endpoint, a website with static content, or a web application with dynamic content and an associated database. On receipt, the HTTP server processes the request and returns a response.

You can use App Connect to pass key data from an app into an HTTP invoke action that calls out to an HTTP endpoint, and then pass data returned from the HTTP response into other apps.

Availability:
  • App Connect connector
  • A local connector in a Designer instance of IBM App Connect in containers (Continuous Delivery release)Local connector in containers (Continuous Delivery release)
  • A local connector in a Designer instance of IBM App Connect in containers (Support Cycle 2)Local connector in containers (Long Term Support Cycle-2 release)

A business scenario

Your company plans to host a week-long outdoor event, with anticipated attendance figures that run into the thousands. You've set up the event in your ticketing app so potential attendees can book tickets. When each attendee registers, you'd like to send them an email with additional details about the event. And because the event is outdoors, it would be a nice touch to help the attendees dress appropriately for the weather by including a weather forecast for each day booked. But, you've got a lot going on and you're hoping there's a quick-and-easy way to ensure each attendee receives the relevant forecast.

How can App Connect help?

Use App Connect to set up a flow that queries the Weather API, and then uses the response to add details about the weather forecast to generated emails whenever an attendee registers for your event. By automating this process, you'll free up time to spend doing what really matters – organizing a top-notch event that your attendees will be raving about for years!

What to consider first

If the HTTP server is in a private network (for example, behind a firewall in an on-premises location or in a private cloud), create a private network connection for App Connect to use to securely access the HTTP server. For more information, see Connecting to a private network.

Connecting to HTTP

To connect App Connect to an HTTP endpoint, see Connecting to HTTP from App Connect.

General considerations for using HTTP in App Connect

  • (General consideration) You can see lists of the trigger events and actions that are available on the Applications and APIs page of the App Connect Designer.

    For some applications, the events and actions depend on the environment and whether the connector supports configurable events and dynamic discovery of actions. If the application supports configurable events, you see a Show more configurable events link under the events list. If the application supports dynamic discovery of actions, you see a Show more link under the actions list.

  • (General consideration) If you are using multiple accounts for an application, the set of fields that is displayed when you select an action for that application can vary for different accounts. In the flow editor, some applications always provide a curated set of static fields for an action. Other applications use dynamic discovery to retrieve the set of fields that are configured on the instance that you are connected to. For example, if you have two accounts for two instances of an application, the first account might use settings that are ready for immediate use. However, the second account might be configured with extra custom fields.
  • For the Invoke method action:
    • The supported HTTP methods are: GET, POST, PUT, PATCH, DELETE, and HEAD.
    • The HTTP and HTTPS transports are supported, and the URL that you specify must be fully qualified. Examples:

      http://www.example.com/

      https://host_name:port/path

      https://my_API_URL?query_parameter1=value1&query_parameter2=value2

      The URL can also contain mappings from previous nodes in the flow. The following example shows a Postal/Zip Code mapping that was inserted using Insert a referenceInsert a mapping icon:

      HTTP URL field showing a combination of text and mapped fields

      Note: If you specified an override URL when connecting to the HTTP account, the protocol, host name, and port that you specify in the URL (fully qualified) field will be replaced with your override settings when the flow runs.
    • Request headers (if required to define additional operating parameters) can be specified as data properties (with a name and String data type) or as a JSON object that consists of comma-separated name/value pairs.
      • To specify request headers as data properties:
        1. Click Add property to define each property with a data type of String.

          Adding properties for request headers

        2. Click Edit mappings to expose these properties as fields and then specify their values. (To add or remove properties, you can click Edit properties.)

          Request headers properties exposed as fields

          To update the name of a defined property, you must ensure that the associated field is empty before you click Edit properties. For more information about specifying data properties, see Defining your own data properties.

      • To specify request headers as JSON (for example {"Accept": "application/json", "Content-Type":"application/json"}), click Map to object and then enter the JSON.

        Request headers field with JSON specified

        If you've already defined one or more property fields under the Request headers heading, but would prefer to use JSON instead, you must delete those properties and then click Map to object to display a Request headers field that you can type into.

    • Optionally implement your own error handling within the flow by indicating whether the flow should continue if something unexpected occurs. Set Continue flow (non-2xx) to true to continue running the flow if a status code other than 2xx (Success) is returned by the HTTP call.

      Continue flow (non-2xx) field for the Invoke method action

      If set to false (the default), flow processing stops when a non-2xx status code is issued.

    • A maximum of three attempts are made to call the HTTP server, with a five-second delay between retries. A flow will typically time out after 60 seconds.

Ways of processing the HTTP response

The response from an HTTP invoke method is returned in a format supported by the endpoint – for example, JavaScript Object Notation (JSON), XML, or CSV format – and is passed as a string. To map the response headers and response body in a subsequent action in your flow, you'll need to use one of the built-in parsers in App Connect to convert the string into an object that represents the string. For example, if the response is in JSON format, you can use the JSON parser to convert the JSON string into a JSON object. You can map to the response by selecting either Response headers or Response body (as appropriate) under HTTP / Invoke method in the list of available inputs.

Response mappings in the list of available inputs

For more information about using the App Connect parsers which are available in the toolbox, see:

Troubleshooting tips

  • If you observe network errors for an HTTP Invoke method action in your flow, the cause might be related to connectivity or security issues. Use these tips to help with error resolution:
    • Verify that the network is available and that the HTTP server can be reached. For example, the error might be due to a network timeout.
    • If you can successfully call out to the HTTP endpoint using a utility such as Postman, verify that your request header specifications in that utility are identical to those specified in the Request headers field of your HTTP node.
    • Investigate whether the issue is caused by SSL certificate errors. App Connect uses Transport Layer Security (TLS) to establish a secure communication channel to the HTTP endpoint, and will reject the certificate that a target server presents if issues are detected; for example, if it's untrusted or expired, or has missing intermediate (or chain) certificates.

      If you can successfully call out to the HTTP endpoint using an external utility, check whether SSL certificate checking is enabled for that utility. If it isn't, you can enable it and test the call again to see whether it passes.

    • To help you determine the cause of the error, ensure that the Continue flow (non-2xx) field is set to true and then map to the HTTP response status code in a subsequent node in the flow. For example:

      Selecting the HTTP status code response

      Then run the flow again and check to see which status code is returned.

  • When you employ the HTTP connector and specify the Request header field as content-type: application/x-www-form-urlencoded, you need to provide a set of key-value pairs in the corresponding Body field. If you incorporate variables which were established earlier in the flow (by using the Variable node), and any of these variables contain an '&' character, the '&' character serves as a separator between key value pairs. This might lead to the flow producing an outcome that deviates from the expected response.

    For example, consider the setup:

    • Header is set as application/x-www-form-urlencoded and key value pairs of the body is set as colors={{$Setvariable.variable.colors}}&pets={{$Setvariable.variable.pets}}.

      The request header type and the request body values

    • The variable is set as colors=blue pets=dog&cat.

      The variable values

    • The test considers the '&' character as a separator and the result is "colors": "blue", "dog": "", "pets": "cat".

      The test result

    Tip: To avoid using '&' character as a separator, you can use proper URL encoding for the "&" character. However, not all websites support this encoding method.

Events and actions

HTTP events

These events are for changes in this application that trigger a flow to start completing the actions in the flow.

Note: Events are not available for changes in this application. You can trigger a flow in other ways, such as at a scheduled interval or at specific dates and times.

HTTP actions

Your flow completes these actions on this application.

Request
Invoke method

Examples

Dashboard tile for a template that uses HTTP

Use templates to quickly create flows for HTTP

Learn how to use App Connect templates to quickly create flows that complete actions on HTTP. For example, open the Templates gallery, and then search for HTTP.

Dashboard tile for a template that uses HTTP