# DigiParser Custom Code Export | Run JavaScript After Extraction

Source: https://www.digiparser.com/integrations/custom-code-export

[<- All integrations](/integrations)

Custom Code Export

# Find the customer.  
Create the record.  
Send the lines.

Run JavaScript after extraction and post-processing. Use the document data, saved secrets, and HTTP calls to build the export your destination API needs.

[Start free ↗](https://app.digiparser.com/auth/join)[Setup documentation ->](/docs/guides/integrations/custom-code-export)

### One export. Your sequence.

1.  Look up an existing customer
2.  Create the customer if missing
3.  Create the sales record
4.  Send each extracted line item
5.  Return the destination record ID

Example workflow; your code defines the requests.

## Build the export sequence your system needs.

Use JavaScript to connect lookups, record creation and line-item requests. Keep credentials in saved secrets and control the sequence in your export code.

1.  1Read the extracted fields and saved secrets.
2.  2Look up the destination records your export needs.
3.  3Create the record and send its line items.

![](/_next/image?url=%2Fimages%2Fintegrations%2Fcustom-code-export-workflow-v1.webp&w=3840&q=75&dpl=dpl_4CEHPWQCJofunboV6oYnMCcudHh5)

## The values available to your code

Custom Code Export runtime

Variable

Purpose

data

Extracted fields and tables

document

Document ID, name, URL, parser ID and workflow run ID

secrets

Private values saved in the Secrets tab

axios

HTTP requests to destination services

console.log()

Execution logs for testing and diagnosis

Use asynchronous requests, functions, loops, conditions, and error handling. Keep the complete export within the 30-second execution limit.

## Keep credentials out of the code

1.  01
    
    ### Add the export
    
    Open Integrations -> Direct exports -> Custom Code Export.
    
2.  02
    
    ### Add named secrets
    
    In the Secrets tab, add a name such as ACCOUNTING\_API\_KEY and its value. Saved values are hidden and can be replaced or deleted.
    
3.  03
    
    ### Write the destination logic
    
    In the Code tab, use data and document for the source values, secrets for credentials, and axios for API calls.
    

// Illustrative request; adapt to your API.
const result = await axios.post(
  "https://api.example.com/records",
  {
    reference: document.id,
    invoice: data\["Invoice Number"\],
  },
  { headers: {
    Authorization: \`Bearer ${secrets.ACCOUNTING\_API\_KEY}\`
  }}
);
return { id: result.data.id };

## Use AI to draft the code, then inspect the requests

Ask AI to Write Code can use your instructions, current code, selected document data, available runtime variables, and secret names. Saved secret values are not sent to the AI.

The generated code replaces the editor contents. It is not saved or run automatically. Review the destination URLs, field names, lookups, and duplicate-prevention logic before testing.

## Test with a processed document

1.  01
    
    ### Select the sample
    
    Choose a representative processed document under Test with a processed document.
    
2.  02
    
    ### Run Test deliberately
    
    Tests make real API calls and can create or update destination records. Use an appropriate test destination and sample.
    
3.  03
    
    ### Inspect status, logs, and output
    
    Check the created or updated record in the destination and examine the returned result.
    
4.  04
    
    ### Save code
    
    Save the verified code. Future exports run after processing and any required approval.
    

## Design for the runtime's limits

### 30 seconds

Complete the full sequence within the execution window. Use your own receiver for longer jobs.

### No automatic retry

Handle failures deliberately. Use document.id as a duplicate-prevention key when the destination supports it.

### One export per parser

The code can call multiple services. Package installation and access to DigiParser files, databases, or environment variables are unavailable.

A failed code export is recorded in the document workflow history. The document remains processed, and other configured exports continue.

[Start free ↗](https://app.digiparser.com/auth/join)[Setup documentation ->](/docs/guides/integrations/custom-code-export)