> ## Documentation Index
> Fetch the complete documentation index at: https://stedi.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate outbound EDI files with fragments

<Note>
  This functionality is available in a Stedi module. [Contact us](https://www.stedi.com/contact) for details.
</Note>

Once you [configure fragments](/edi-platform/fragments/index) for a transaction type, you can use Stedi's APIs to generate EDI files from fragments.

For example, if you enable fragments on the `INS` loop in an 834 Health Care Benefit Enrollment and Maintenance, you can send batches of `INS` loops to Stedi's [Stage Fragment API](/api-reference/edi-platform/core/post-fragments), and Stedi will securely store them until you're ready to send the complete file.

Once you stage all the fragments, you call the [Create Outbound Transaction API](/api-reference/edi-platform/post-transactions) to combine the fragments together into a single EDI file and deliver it to your trading partner.

## Find the Guide JSON Schema

Unless you're using [mappings](/edi-platform/mappings), you must send fragments in [Guide JSON](/edi-platform/operate/transform-json/guide-json), a JSON format that matches the JSON Schema of the guide associated with the outbound transaction setting.

To find the JSON Schema for a fragment:

1. Navigate to the [Trading partners page](https://portal.stedi.com/app/core/partnerships).
2. Select the partnership.
3. Click the name of the guide associated with the outbound transaction setting.
4. Open the **Actions** menu and select **View schema**.
5. Find the segment that you selected to split the file. The shape for that segment is the JSON Schema you must use when sending fragments to Stedi.

The following example shows the JSON Schema for `Loop 2000` (Member Level Detail) in an 834 Healthcare Benefit Enrollment and Maintenance transaction. The start of this loop is the `INS` segment, which is where Stedi will split the file.

<Accordion title="Example JSON Schema for Loop 2000 in an 834">
  <Snippet file="example-json-schema-ins-loop.mdx" />
</Accordion>

## Find the mapping ID and schema

If you plan to use a mapping to transform fragments into Stedi’s Guide JSON format, you must send fragments to Stedi's API in the mapping's source JSON schema.

To find the mapping ID and schema:

1. Go to the [Mappings page](https://portal.stedi.com/app/mappings) and copy the **ID** field for the mapping you want to use.
2. Click the mapping's name to view its details.
3. Click **Test mapping**. The test input JSON shape is the shape you must use when sending fragment data to the Stage Fragment API.

## Stage fragments

Call the [Stage Fragments API](/api-reference/edi-platform/core/post-fragments) to store a fragment on Stedi until you are ready to generate an outbound EDI file.

Stedi stores fragments in groups, specified by the `fragmentGroupID` included in the path. You can call the API with the same `fragmentGroupID` as many times as needed until you have staged all of the fragments required for the transaction.

### Data format

For each staging call, you can optionally specify a mapping that Stedi will use to transform the fragment from your system's JSON format into Stedi’s Guide JSON format.

* If you don’t use a mapping, the fragment must match the Guide JSON format for the specified guide.
* If you use a mapping, the fragment must match the mapping's source JSON schema.

### Sample request and response

The following example shows a cURL request and response for staging a fragment without a mapping. The fragment contains iterations of `Loop 2000` (Member Level Detail) in an 834 Healthcare Benefit Enrollment.

<Snippet file="api-examples/core/stage-fragments.mdx" />

## Create outbound transaction

Call the [Create Outbound Transaction API](/api-reference/edi-platform/post-transactions) and Stedi combines all of the fragments matching the `fragmentGroupId` into a single, compliant EDI file and delivers it to your trading partner.

Once you call the Transaction API with a `fragmentGroupId`, that ID is locked, meaning that you cannot add new fragments to the group and you cannot call the API again with that ID. This feature prevents you from accidentally sending duplicate data to partners.

### Data format

When calling the API with fragments, you provide a *fragment wrapper* for the transaction. The wrapper contains all of the transaction data except for the contents of the repeated loop segment where Stedi should insert the fragments. Instead, you leave an empty array in place of the loop contents - for example, `member_level_detail_INS_loop: []`.

<Accordion title="Fragment wrapper for an 834 benefit enrollment">
  ```json
  "transaction": {
      "heading": {
          "transaction_set_header_ST": {
              "transaction_set_identifier_code_01": "834",
              "transaction_set_control_number_02": 12345,
              "implementation_convention_reference_03": "005010X220A1"
          },
          "beginning_segment_BGN": {
              "transaction_set_purpose_code_01": "00",
              "transaction_set_reference_number_02": "12456",
              "transaction_set_creation_date_03": "1998-05-20",
              "transaction_set_creation_time_04": "12:00",
              "action_code_08": "2"
          },
          "payer_N1_loop": {
              "payer_N1": {
                  "entity_identifier_code_01": "IN",
                  "identification_code_qualifier_03": "FI",
                  "insurer_identification_code_04": "654456654"
              }
          },
          "sponsor_name_N1_loop": {
              "sponsor_name_N1": {
                  "entity_identifier_code_01": "P5",
                  "identification_code_qualifier_03": "FI",
                  "sponsor_identifier_04": "999888777"
              }
          }
      },
      "detail": {
          "member_level_detail_INS_loop": []
      }
  }
  ```
</Accordion>

You can optionally provide a mapping ID to transform the fragment wrapper from your system's JSON format into Stedi’s Guide JSON format. If you don't use a mapping, the fragment wrapper must match the Guide JSON format for the specified guide.

### Sample request and response

The following example shows a cURL request and response to generate an [834 Benefit Enrollment and Maintenance](https://portal.stedi.com/app/guides/view/hipaa/benefit-enrollment-and-maintenance-x220a1/01GRYB6D6RAWSG8ATBD6GXM13C). Notice that the `member_level_detail_INS_loop` is an empty array - this is where Stedi will insert the fragments from the specified fragment group.

<Snippet file="api-examples/core/create-transaction-with-fragments.mdx" />

## Retrieve an outbound transaction with fragments

Call the [Get Transaction](/api-reference/edi-platform/core/get-transactions) endpoint to retrieve the full transaction, including the fragment data. Note that the full transaction, including fragments, can be very large.
