Response Rejection


The purpose of @flatfile/util-response-rejection utility is to handle cases where some Records were rejected during an egress process. The responseRejectionHandler function is designed to consume a set of sheets containing rejected Records, and then process the rejected Records by marking the offending Record fields with the returned rejection message indicating why they were rejected. In the end, it returns a total count of all rejected Records across all sheets that can be used in a Job completion message.

npm i @flatfile/util-response-rejection
import { responseRejectionHandler } from "@flatfile/util-response-rejection";

Response Rejection Handler Function

  • The responseRejectionHandler function is the main entry point of the utility. It takes one parameter:
    • responseRejection: An object containing the rejection data. This object’s structure is defined by the ResponseRejection interface.
  • The responseRejectionHandler function returns a Promise that resolves to a number representing the total number of rejected Records across all sheets.
  { job: "workbook:submitActionFg" },
  async ({ context: { jobId } }) => {
    // ...
    const response = await"", data, {
      headers: {
        "Content-Type": "application/json",

    const rejections: ResponseRejection =;
    if (rejections) {
      const totalRejectedRecords = await responseRejectionHandler(rejections);
    // ...

ResponseRejection Interface

The ResponseRejection interface defines the structure of the responseRejection parameter object that is passed into the responseRejectionHandler function. This ResponseRejection’s structure is as follows:

{ // ResponseRejection interface
  id: string; // The Workbook ID
  sheets: [
    { // ResponseRejectionSheet interface
      id: string; // The Sheet ID
      rejectedRecords: [
        { // ResponseRejectionRecord interface
          id: string; // The Record ID
          values: [
              field: string; // The field name
              message: string;
        // ...
    // ...

Helper Functions

  • The code includes a helper functions to assist in the Flatfile Sheet update process:
    • updateSheet: Updates a Flatfile Sheet by adding the returned rejection messages as error messages on the Records.

Type Definitions

  • The code defines three interfaces: ResponseRejection, ResponseRejectionSheet and ResponseRejectionRecord. These interfaces represent the structure expected by the responseRejectionHandler().

See the code