Epicor Rest Helper for Node (npm) V2.0

Version 1.2.7

:tada: New Features

Response Headers Capture

Added the ability to capture HTTP response headers from all API calls using the new [CapturedResponseHeaders] class.

What’s New:

  • New Class: [CapturedResponseHeaders] - A utility class for capturing and managing HTTP response headers
  • Enhanced API Methods: All API methods now accept an optional capturedResponseHeaders parameter as the last argument
  • Header Access Methods:
    • getHeader(name)- Get specific headers (case-insensitive)
    • hasHeader(name) - Check if a header exists
    • getHeaderNames()- Get all header names
    • headers property - Access all headers as an object
    • clear() - Clear captured headers

Supported Methods:

  • [BoGet], [BoPost], [BoPatch], [BoDelete]
  • [BaqGet], [BaqPatch], [BaqMetaData]
  • [EfxPost]
  • [GetFunctionLibraryList], [GetFunctionLibrarySpec]
  • [GetEnvironment]

Example Usage:

import { CapturedResponseHeaders } from 'epicor-rest-node';

const capturedHeaders = new CapturedResponseHeaders();

const result = await service.GetEnvironment(null, null, capturedHeaders);

// Access headers

console.log('Content-Type:', capturedHeaders.getHeader('content-type'));

console.log('All headers:', capturedHeaders.headers);

:wrench: Technical Changes

  • Import Updates: Added [CapturedResponseHeaders] to exports in main module
  • Type Safety: Full TypeScript support with proper typing for all new functionality
  • Backward Compatibility: All existing code continues to work without changes - the new parameter is optional
  • Error Handling: Response headers are captured even when API calls return errors (when response object is available)

:light_bulb: Use Cases

The new response headers capture feature enables:

  • Debugging: Examine server response headers for troubleshooting
  • Rate Limiting: Access rate limiting information and quotas
  • Custom Logic: Extract custom Epicor headers with business information
  • Performance Monitoring: Monitor server performance metrics
  • Caching: Implement caching strategies based on cache-control headers
  • Security: Security auditing and compliance logging
  • Tracing: Epicor supports passing in addtional trace headers to a call. You can now do this using the additionalHeaders and the capture headers thanks @Olga for the suggestion

IE: You can pass in an optional header as such to enable server side tracing. See Performance Tunning Guide for a complete list of trace flags.

const capturedHeaders = new CapturedResponseHeaders();
const optionalHeaders = {"TraceFlags":"{\"FlagList\":[\"trace:\/\/system\/fw\/trigger\",\"trace:\/\/system\/db\/hits\",\"trace:\/\/ice\/fw\/BPM\",\"trace:\/\/ice\/fw\/DynamicQuery\"],\"UseServerTiming\":false}"};  
var map = new Map<string, string>();
map.set('whereClause', '');
map.set('pageSize', '0'); // Limit results for testing
map.set('absolutePage', '0');
result = await this.service.BoGet("Erp.BO.CompanySvc","GetList",map,null, optionalHeaders, capturedHeaders);

//the capturedHeaders object will contain the aformentioned headers including the new callertrace

Which will then Return the following as Part of the capture response headers.

{"callertrace": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTE2Ij8+DQo8T3AgVXRjPSI yMDI1LTA4LTEzVDE4OjQ2OjAxLjYzNjI3ODFaIi
BhY3Q9IkVycDpCTzpDb21wYW55L0NvbXBhbnlTdmNDb250cmFjdC9HZXRMaXN0IiBjb3JyZWxhdGlvbklkPSJjNTM2ZTdmOC1kOWMyLTQ3ZjQtODEwYy0yMDdhMGE4ZTE0ZDUiIGR1cj0iNC4xMjYxIiBjbGk9IjEwLjI1NC4xLjIwMDo1MDQwNiIgdXNyPSJqY2dvbWV6IiBtYWNoaW5lPSJBWi1FUElDT1ItREVWMDEiIHBpZD0iMTEzNTgwIiB0aWQ9IjMyIj4NCiAgPFNxbCBxdWVyaWVzPSIxIiBjYWNoZUhpdHM9IjAiIHRpbWU9IjAuNjQxOCIgcXJ5VHlwZUNvdW50PSIxIiAvPg0KPC9PcD4="}

Which you if you haven’t guessed by now is a base64 encoded string which contains… you guessed it a Tracecall

<?xml version="1.0" encoding="utf-16"?>
<Op Utc="2025-08-13T18:46:01.6362781Z" act="Erp:BO:Company/CompanySvcContract/GetList" correlationId="c536e7f8-d9c2-47f4-810c-207a0a8e14d5" dur="4.1261" cli="10.254.1.200:50406" usr="jcgomez" machine="AZ-EPICOR-DEV01" pid="113580" tid="32">
  <Sql queries="1" cacheHits="0" time="0.6418" qryTypeCount="1" />
</Op>
5 Likes