Overview
PromoStandards APIs return responses in XML format by default (SOAP protocol requirement). The SDK provides automatic conversion to JSON for easier JavaScript/TypeScript integration.Choosing a Response Format
The SDK supports two response formats, controlled by theformat parameter:
When to Use Each Format
JSON (Recommended)
- Default and most convenient for JavaScript/TypeScript
- Easy to work with in modern applications
- Native JavaScript object manipulation
- Ideal for most use cases
XML
- When you need raw SOAP responses
- Custom XML parsing requirements
- Debugging or logging raw responses
- Integration with XML-based systems
JSON Response Format (Default)
By default, the SDK automatically converts XML responses to JSON using theconvertXMLtoJSON utility.
Example JSON Response
Working with JSON Responses
XML Response Format
Whenformat: 'xml' is specified, the SDK returns raw XML strings from the SOAP service:
Example XML Response
XML to JSON Conversion Process
The SDK uses theconvertXMLtoJSON utility (from Utils.ts:29-50) to transform XML responses:
Conversion Implementation
Conversion Features
Namespace Stripping
Namespace Stripping
XML namespaces are automatically removed for cleaner JSON keys:
Type Conversion
Type Conversion
String values are automatically converted to appropriate types:
Array Handling
Array Handling
The SDK intelligently handles arrays using two mechanisms:1. explicitArray: falseSingle items are NOT wrapped in arrays, multiple items are:2. Array Tag DetectionTags ending in “Array” are forced to arrays (Utils.ts:16-27):
Attribute Handling
Attribute Handling
XML attributes are ignored by default (
ignoreAttrs: true):PromoStandards rarely uses XML attributes, so this simplifies the JSON structure.
How Format is Applied
From PromoStandards.ts:147-151, the format is checked before returning the response:Handling Arrays in JSON Responses
PromoStandards responses contain many arrays (colors, sizes, pricing, etc.). The SDK handles these intelligently:Safe Array Access
Using ensureArray Helper
The SDK’s internalensureArray utility (Utils.ts:4) can be useful:
Response Format Best Practices
Use JSON by Default
JSON is easier to work with in JavaScript and is the recommended format for most applications.
Handle Missing Data
Always use optional chaining (
?.) when accessing nested response properties.Validate Arrays
Check if array fields are actually arrays before iterating, or use
ensureArray.Log Raw Responses
During debugging, temporarily switch to XML format to see raw SOAP responses.
Debugging with XML Format
When troubleshooting API issues, XML format helps you see the raw SOAP response:Switching Formats Dynamically
The format is set during client initialization, but you can create multiple clients:Next Steps
Client Configuration
Learn about configuring the PromoStandards Client
Error Handling
Handle errors in API responses