Upload and List a File

This use case demonstrates how to use the OpenAI Adapter to upload a file to an OpenAI account in one integration and list the uploaded file in another integration.

Upload a File

Let's look at how to upload a file in an integration to an OpenAI account using the Upload file API.

  1. Configure a REST Adapter trigger connection and OpenAI Adapter invoke connection.
  2. Create an application integration.
  3. Drag the REST Adapter trigger connection into the integration canvas for configuration. For this example, the REST Adapter is defined as follows:
    • The Resource Configuration page is defined as follows:
      • A REST Service URL of /triggerUploadFile is specified for this example.
      • A Method of POST is selected.
      • The following request and response options are selected:
        • Configure a request payload for this endpoint
        • Configure this payload to receive the response
    • The following Request page options are selected:
      • Request is multipart with payload
      • Multipart request is of type multipart/form-data with HTML form payload
    • The sample JSON payload is specified on the Response page:
      {
        "object" : "file",
        "id" : "file-BMhhwR9ip3saFknosY9HWr",
        "purpose" : "fine-tune",
        "filename" : "sample.jsonl",
        "bytes" : 233,
        "created_at" : 1759841814,
        "expires_at" : null,
        "status" : "processed",
        "status_details" : null 
      }
  4. Open the request mapper, and map the following source elements to target elements.
    • The source Attachment Reference element is mapped to the target Stream Reference element. These elements are displayed because of the multipart selections made on the Request page when defining the REST Adapter trigger connection.
    • The source Parameter element is mapped to the target Purpose element. The Purpose element is required. It describes the intended purpose of the uploaded file and is part of the Upload file API. See Upload file.


    Three icons are shown at the top left. The Developer link, XSLT link, and six other icons are shown at the top right. Above these icons is the Validate icon. Below this, the Sources, Mapping canvas, and Target sections are shown. The source Attachment Reference is mapped to the target Stream Reference. The source Parameter is mapped to the target Purpose.

  5. Expand the source Attachment Properties element, and map the source Body elements to the target elements to define file metadata. The Part Name element mapping is required, but the other elements are optional.


    Three icons are shown at the top left. The Developer link, XSLT link, and six other icons are shown at the top right. Above these icons is the Validate icon. Below this, the Sources, Mapping canvas, and Target sections are shown. The source Attachment Properties is expanded, and source elements are mapped to File Metadata target elements.

  6. Drag the OpenAI Adapter invoke connection into the integration canvas and configure it as follows.
    1. On the Basic Info page, select Upload file from the Action list.
    2. On the Summary page, view your selection. No additional configuration in the Adapter Endpoint Configuration Wizard is required.
  7. Open the response mapper.
  8. Map the source Body elements under UploadFile Response (OpenAI) to the target elements.

    These elements are the parameters defined in the Upload file API response structure. See Upload file.


    Three icons are shown at the top left. The Developer link, XSLT link, and six other icons are shown at the top right. Above these icons is the Validate icon. Below this, the Sources, Mapping canvas, and Target sections are shown. The source UploadFile Response (OpenAI) is expanded, and source Body elements are mapped to File Response Wrapper target elements.

  9. Specify the business identifier and activate the integration.

    The completed integration looks as follows:


    The completed integrations shows a trigger, map, invoke, and map.

  10. From the Actions Actions icon menu, select Run.

    The Configure and run page appears.

  11. In the Body field of the Request section, define the following content, then click Run.
    1. Deselect the default files parameter. This action is required because OpenAI expects the parameter name to be file, and not files.
    2. Add a new parameter named file, and select File from the list.
    3. Upload the attachment file (for this example, sample.pdf is selected).
    4. Add a new parameter named purpose, select Text from the list, and enter an OpenAI-supported value for this parameter (for this example, user_data is entered). For the list of supported values, see Upload file.


      The Request section includes tabs for URI parameters, Headers, Body (which is selected), cURL, and Integration properties. The files parameter is deselected. The file parameter is defined with a type of File and an uploaded file. The purpose parameter is defined with a type of Text and a value of user_data.

      The Body field of the Response section returns the following output. The id parameter uniquely identifies the value for the uploaded file.


      The Response section shows a status of 200 and the instance ID. below this is the Body tab (which is selected) and the Headers tab. The Body tab shows the output returned from running the integration.

  12. Expand the activity stream to view additional details.

List the Uploaded File

Let's look at how to list the uploaded file in another integration. The List files API lets you obtain a list of all files you previously uploaded to your OpenAI account.

  1. Create an application integration.
  2. Drag the REST Adapter trigger connection into the integration canvas for configuration. For this example, the REST Adapter is defined as follows:
    • The Resource Configuration page is defined as follows:
      • A REST Service URL of /triggerOpenAIListFiles is specified for this example.
      • A Method of GET is selected.
      • The following request and response options are selected:
        • Add and review parameters for this endpoint
        • Configure this endpoint to receive the response
    • The Request Parameters page lists the query parameters defined by the List files API. Select the appropriate parameters to use based on your requirements. See List files.


      The Edit Request Parameters page is shown for the REST Adapter trigger connection. The HTTP method is GET. The Add and Remove buttons are shown. The after, limit, order, and purpose query parameters are shown, along with their specific data types.

    • The sample JSON payload is specified on the Response page:
      {
        "object" : "list",
        "data" : [{
         "id" : "file-abc123",
         "object" : "file",
         "bytes" : 175,
         "created_at" : 1613677385,
         "expires_at" : 1677614202,
         "filename" : "salesOverview.pdf",
         "purpose" : "assistants"
        },{
         "id" : "file-abc456",
         "object" : "file",
         "bytes" : 140,
         "created_at" : 1613779121,
         "expires_at" : 1677614202,
         "filename" : "puppy.jsonl",
         "purpose" : "fine-tune"
        }],
         "first_id" : "file-abc123",
         "last_id" : "file-abc456",
         "has_more" : false
      }
  3. Open the request mapper.
  4. Map the query parameters. These are the parameters that where displayed on the Request Parameters page when you configured the REST Adapter invoke connection. If you do not map any of these parameters, they are ignored at runtime.


    Three icons are shown at the top left. The Developer link, XSLT link, and six other icons are shown at the top right. Above these icons is the Validate icon. Below this, the Sources, Mapping canvas, and Target sections are shown. The source Query Parameters elements are mapped to target Request Wrapper elements.

  5. Drag the OpenAI Adapter invoke connection into the integration canvas and configure it as follows.
    1. On the Basic Info page, select List files from the Action list.
    2. On the Summary page, view your selection. No additional configuration in the Adapter Endpoint Configuration Wizard is required.
  6. Open the response mapper.
  7. Map the following source Body elements under ListFiles Response (OpenAI) to the target elements.


    Three icons are shown at the top left. The Developer link, XSLT link, and six other icons are shown at the top right. Above these icons is the Validate icon. Below this, the Sources, Mapping canvas, and Target sections are shown. The source ListFiles Response (OpenAI) is expanded, and source Body elements are mapped to File Response Wrapper target elements.

  8. Expand the target Data element and perform additional mapping.


    Three icons are shown at the top left. The Developer link, XSLT link, and six other icons are shown at the top right. Above these icons is the Validate icon. Below this, the Sources, Mapping canvas, and Target sections are shown. The source ListFiles Response (OpenAI) is expanded, and source Body elements are mapped to Response Wrapper target elements.

  9. Specify the business identifier and activate the integration.

    The completed integration looks as follows:


    The integration shows a trigger, map, invoke, and map.

  10. From the Actions Actions icon menu, select Run.

    The Configure and run page appears.

  11. In the URI parameters field of the Request section, select the query parameters to use, specify values, and click Run. For this example, the following parameters are defined.


    The Request section includes tabs for URI parameters (which is selected), Headers, Body, cURL, and Integration properties. The purpose, limit, after, and order parameters are shown. Values are defined for purpose, limit, and order.

    .
  12. View your results. Three entries in which purpose is defined as user_data are displayed in descending order in the Response section. Here is a small portion of the output. Note that the original ID of the file uploaded (first_id) in Upload a File is automatically displayed.


    The Response section shows a status of 200 and the instance ID. below this is the Body tab (which is selected) and the Headers tab. The Body tab shows the output returned from running the integration.

  13. Expand the activity stream to view additional details.