Skip to main content

Call an HTTP Service (APIs, Rest)

HTTP task allows for making calls to remote services exposed over HTTP/HTTPS.

Definitions

  {
"name": "http",
"taskReferenceName": "http_ref",
"type": "HTTP",
"inputParameters": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"encode": true,
"headers": {
"If-Range": "${workflow.input.range}"
},
"body": {
"key": "value"
}
},
"cacheConfig": {
"ttlInSecond": 2500,
"key": "cache-key"
},
"optional": false,
"asyncComplete": true
}

Input Parameters

AttributeDescription
uriProvide the URI for the service. It can be a partial value when using vipAddress or it can be the server address.
methodChoose the HTTP method. Conductor supports the methods: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, and TRACE.
acceptProvide the accept header as required by the server. The supported types are:
  • application/java-archive
  • application/EDI-X12
  • application/EDIFACT
  • application/javascript
  • application/octet-stream
  • application/ogg
  • application/pdf
  • application/xhtml+xml
  • application/x-shockwave-flash
  • application/json
  • application/ld+json
  • application/xml
  • application/zip
  • application/x-www-form-urlencoded
  • audio/mpeg
  • audio/x-ms-wma
  • audio/vnd.rn-realaudio
  • audio/x-wav
  • image/gif
  • image/jpeg
  • image/png
  • image/tiff
  • image/vnd.microsoft.icon
  • image/x-icon
  • image/vnd.djvu
  • image/svg+xml
By default, it is set to application/json. You can also pass any other headers as variables.
contentTypeProvide the content type for the server. The supported types are:
  • application/java-archive
  • application/EDI-X12
  • application/EDIFACT
  • application/javascript
  • application/octet-stream
  • application/ogg
  • application/pdf
  • application/xhtml+xml
  • application/x-shockwave-flash
  • application/json
  • application/ld+json
  • application/xml
  • application/zip
  • application/x-www-form-urlencoded
  • audio/mpeg
  • audio/x-ms-wma
  • audio/vnd.rn-realaudio
  • audio/x-wav
  • image/gif
  • image/jpeg
  • image/png
  • image/tiff
  • image/vnd.microsoft.icon
  • image/x-icon
  • image/vnd.djvu
  • image/svg+xml
By default, it is set to application/json. You can also pass this parameter as a variable.
headersA map of additional HTTP headers to be sent along with the request. The supported types are:
  • Accept-Language
  • Authorization
  • Cache Control
  • Content-MD5
  • From
  • If-Match
  • If-Modified-Since
  • If-None-Match
  • Max-Forwards
  • Pragma
  • If-Range
  • If-Unmodified-Since
  • Proxy-Authorization
  • Range
  • Warning
  • x-api-key
  • Accept-Charset
  • Accept-Encoding
  • Accept-Control-Request-Headers
  • Accept-Control-Request-Method
  • Content-Transfer-Encoding
  • Expect
  • Transfer-Encoding
  • Trailer
bodyRequest body when using POST, PUT, or PATCH. It can be added as text ("body": "text") or parameters such as string, number, boolean, null, or object/array.
encodeDetermines whether the URI needs encoding. When set to true (the default), the Conductor will automatically encode the query parameters before sending the HTTP request.

Set this to false if the URI is already encoded. In this case, the Conductor will assume the query parameters are properly encoded and pass them to the HTTP endpoint as specified in the URI.
cacheConfigEnabling this option allows saving the cache output of the task. On enabling, you can provide the following parameters:
optionalEnabling this option renders the task optional. The workflow continues unaffected by the task's outcome, whether it fails or remains incomplete.
asyncCompleteWhen turned on, task completion occurs asynchronously, with the task remaining in progress while waiting for external APIs or events to complete the task.

Output Parameters

AttributeDescription
responseA JSON object representing the response, if present.
headersAn object containing the metadata about the response.
statusCodeReturns the HTTP status code indicating the success or failure of the request.
reasonPhraseReturns the reason phrase associated with the HTTP status code.
bodyReturns the body of the response containing the actual data returned by the API.

Examples



  1. Add task type HTTP.
  2. Configure the task by choosing method, endpoint, headers, etc.

Adding HTTP task

Sample Task Definition for sending a POST request

    {
"name": "http_post_example",
"taskReferenceName": "post_example",
"inputParameters": {
"http_request": {
"uri": "https://jsonplaceholder.typicode.com/posts/",
"method": "POST",
"body": {
"title": "${get_example.output.response.body.title}",
"userId": "${get_example.output.response.body.userId}",
"action": "doSomething"
}
}
},
"type": "HTTP"
}

Sample Workflow utilizing “Async Complete” option

The "asyncComplete" option in the HTTP task configuration allows tasks to be marked as completed asynchronously, providing flexibility in workflow execution. Let's examine a detailed example to better understand its implementation.

Here’s a sample workflow with “asynComplete” set to “true”:

{
"name": "async_complete_example",
"description": "Edit or extend this sample workflow. Set the workflow name to get started",
"version": 1,
"tasks": [
{
"name": "http_task_85tf2",
"taskReferenceName": "http_task_85tf2_ref",
"inputParameters": {
"http_request": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json"
}
},
"type": "HTTP",
"asyncComplete": true
}
],
"schemaVersion": 2,
"ownerEmail": "devrel@orkes.io"
}

Now, let’s run this in the Playground.

Run in Orkes Playground

  1. Under Workflow Name, choose async_complete_example.
  2. Click Run Workflow.

Upon execution, the HTTP task remains “Scheduled” instead of completing immediately, allowing for asynchronous completion. There are various methods to update the task status to complete:

Using API

Once the workflow runs, note the generated workflowId displayed beneath the workflow name on the execution page.

Workflow ID in Conductor

Utilize this workflowId along with the taskRefName to complete the task through the following API:

POST /api/tasks/{workflowId}/{taskRefName}/{status}

Another method is to directly update from the UI.

From Conductor UI

From the workflow execution page, click on the task and manually update the status to “COMPLETED.”

Updating workflow status from Conductor UI

Employing these methods allows you to asynchronously complete your workflow, which is beneficial when pausing the workflow for external interventions.