Ask AI
Skip to main content

Fetch a file

Function: Fetch a file

Effortlessly connect and fetch a file, simplifying data integration and enhancing the functionality of your applications through a user-friendly, code-free interface. This action allows your application to retrieve files from external web services (APIs) using either GET or POST requests, and then store the downloaded file within your application for further use.

Input,

  • Authentication method: Choose how you want to prove your identity to the external service.
    • Basic authentication: Use a username and password.
    • Bearer Token: Use a special token (like a key) to get access.
    • Api Token: Similar to a Bearer Token, but often used for specific API keys.
    • None: No authentication is needed.
  • Username: (Only appears if "Basic authentication" is chosen) Your username for logging into the external service.
  • Password: (Only appears if "Basic authentication" is chosen) Your password for logging into the external service.
  • Token: (Only appears if "Bearer Token" or "Api Token" is chosen) The secret key or token that grants you access to the external service.
  • Headers: Additional information sent with your request, often used for things like content type or custom authentication details. You can add multiple key-value pairs.
  • Endpoint: The full web address (URL) of the specific resource you want to fetch the file from. This is a required input.
  • Query parameters: Extra pieces of information added to the end of the URL, usually to filter or specify the data you want. You can add multiple key-value pairs.
  • Method: Choose the type of request to send to the external service. This is a required input.
    • GET: Used to request data from a specified resource. (Default)
    • POST: Used to send data to a server to create/update a resource.
  • Request body: (Only appears if "POST" method is chosen) The data you want to send to the external service, typically in a structured format like JSON. You can add multiple key-value pairs or select an existing data object.
  • File name: A name you want to give to the downloaded file when it's stored in your application.
  • File description: A short explanation or note about the downloaded file.

Output,

  • Response: This variable will hold the downloaded file. You can then use this file in other parts of your application.
  • Status: This variable will tell you if the file download was successful or if there were any issues. Possible statuses include:
    • SUCCESS: The file was downloaded successfully.
    • BAD_REQUEST: Your request to the external service was incorrect.
    • UNAUTHORIZED: Your authentication details (username/password or token) were not accepted.
    • NOT_FOUND: The web address (endpoint) you provided does not exist on the external service.
    • TYPE_ERROR: An error occurred while trying to identify the type of the downloaded file.

Execution Flow,

Real-Life Examples,

Example 1: Downloading an Invoice with Basic Authentication

Imagine you have an external accounting system that stores customer invoices. You want to automatically download a specific invoice PDF into your application when a customer's payment is confirmed.

  • Inputs:
    • Authentication method: Basic authentication
    • Username: accounting_user
    • Password: secure_pass123
    • Endpoint: https://api.accounting.com/invoices/INV-2023-001/pdf
    • Method: GET
    • File name: Invoice_INV-2023-001
    • File description: PDF invoice for customer INV-2023-001
  • Result: The PDF file for invoice INV-2023-001 is downloaded and stored in your application under the variable Response. The Status variable will be set to SUCCESS.

Example 2: Fetching a Product Image using an API Token

Your e-commerce platform needs to display product images from a third-party image hosting service. You want to fetch a specific product image using an API token for authentication.

  • Inputs:
    • Authentication method: Api Token
    • Token: your_secret_api_token_xyz123
    • Endpoint: https://images.producthost.com/products/PROD-456/main_image.jpg
    • Method: GET
    • File name: Product_PROD-456_Main_Image
    • File description: Main image for product PROD-456
  • Result: The JPG image file for product PROD-456 is downloaded and available in your application via the Response variable. The Status variable will be SUCCESS.

Example 3: Uploading a Document and Receiving a Confirmation File

You have a workflow where users submit a form, and the data needs to be sent to an external document management system via a POST request. The system then returns a small confirmation file.

  • Inputs:
    • Authentication method: Bearer Token
    • Token: bearer_token_for_doc_system
    • Headers: Content-Type: application/json
    • Endpoint: https://docs.management.com/upload
    • Method: POST
    • Request body:
      \{
      "documentTitle": "New User Agreement",
      "author": "John Doe",
      "date": "2023-10-26"
      \}
    • File name: Upload_Confirmation
    • File description: Confirmation file for document upload
  • Result: The document data is sent to the external system. A confirmation file (e.g., a small text file or JSON) is downloaded and stored in your application as Response. The Status variable will be SUCCESS. If the external system rejects the request due to invalid data, Status might be BAD_REQUEST.