HTTP response returned as a file
  • 20 Feb 2024
  • 3 Minutes to read
  • Dark
    Light

HTTP response returned as a file

  • Dark
    Light

Article Summary

In some cases, you might want to get the response of an HTTP request step as a file, instead of directly to context. For example, when the step returns:

Supported steps

You can return the response as a file for the following steps:

  • Send an HTTP Request step
  • Any step that you can Switch to HTTP Mode

Get the HTTP response as a file

  1.  In the step Properties tab, expand the Execution Options section.
  2.  Set the Return Response as File option to Yes

httprequestfile1

HTTP request output

The HTTP request output is a JSON object.

{
  "api_object": {
    "content_type": "application/json; charset=utf-8",
    "filename": "get",
    "hashes": {
      "md5": "15fff2b2e51d41a12247a0ea1639ee0f",
      "sha1": "9f22dac8bd5bb6aecf6c12cb88ee4cee1e18f465",
      "sha256": "94feff555d530e167f5cc0715760fce4c39baf258409b781ddd01fa9cf284f1a"
    },
    "size": 351,
    "url": "tqfile://steps/e1d63123-d938-46c3-bd5d-51ef9c26c123"
 	}
}

Once you get the response for the Send an HTTP Request step, you can access its data by using the file URL as input for other steps, such as Run jq Command or Extract all using a regex group/pattern.

 🗒️ Note
To access a file URL with the format tqfile://steps/XXXXXXXXX in a subsequent step, use the file inline function: {{file <JSONPath to the URL>}}. For example: {{ file $.send_an_http_request.api_object.url }}. The file inline function isn't required if the file URL is a shareable link.
🗒️ Note
The response file is available for 24 hours. 

The hash functions calculated for the file can be used to scan online threat databases to make sure the file is safe to use.

The ContentType is derived from the HTTP response header. The file content type, name, and size (in bytes) can be used as filter criteria in the following workflow steps.

File URLs with the format tqfile://steps/XXXXXXXXX can only be used in Torq steps and aren't shareable with third parties. To get a shareable link set the Shareable Link toggle to Yes. The Shareable Link toggle is only visible when the Return Response As File toggle is set to Yes.

A shareable link will have the format https://link.torq.io/ ***dEjnLCXnv7 and it can be accessed directly in a subsequent step (doesn't require the file inline function).

httprequestfile2

Binary content (image, PDF file, executable, etc.)

Binary content should only be returned as a file. It's unusable otherwise.

In the following example, we attempted to get an image from the internet into context.

httpsteprequestfile3

The output can't be used in a meaningful way.

httpsteprequestfile4

Instead, you can select to return the response as a file.

httprequestfile1The output is the response file object.

httpsteprequest5

You can pass the file URL to other steps in the workflow by using: {{ file $.send_an_http_request.api_object.url }}

Large output

If the HTTP response exceeds the size limit, the step will fail or disrupt the workflow run. If your step fails for this reason or you expect the step to return a large response, you should set the Return Response as File parameter to Yes.

httprequestfile1The output is the response file object.

httpsteprequestfile6Content of the response file (reference)

{
   "args":{
      "foo1":"bar1",
      "foo2":"bar2"
   },
   "headers":{
      "x-forwarded-proto":"https",
      "x-forwarded-port":"443",
      "host":"postman-echo.com",
      "x-amzn-trace-id":"Root=1-628ca7cc-51450d6752429d686f2390d1",
      "accepted":"application/json; charset=utf-8",
      "user-agent":"TorqHTTPStep/4.0.0",
      "accept-encoding":"gzip"
   },
   "url":"https://postman-echo.com/get?foo1=bar1&foo2=bar2"
}

Below are examples of how you can extract information from the HTTP response file. 

Extract using regex

The Extract all using a regex pattern step will return every match of the regular expression foo* in the HTTP response file. You can also use the Extract all using a regex group step.

httpsteprequestfile7
httpsteprequestfile8

Extract using jq

The Run jq Command step will return the value of the parameter args in the HTTP response file. To use JQ you need prior knowledge of the JSON structure.

httpsteprequestfile9
httpsteprequestfile10


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.