1. Connect to BriteCore ACORD XML API
Path: /api/v2/acord
Method: POST
Request: Valid ACORD XML
Authentication: Caller must authenticate via one of the following ways:
- Provide a valid access key obtained from OAuth 2.0 Client Credentials grant (see this article);
- Provide a BriteCore API Key in HTTP “Authorization” header; or
- Provide a BriteCore API Key in HTTP request body at XPath: ACORD/SignonRq/ClientApp/com.britecore_ApiKey
2. Configure XML Processing Templates
Three templates are involved in ACORD XML processing:
- Router template
- Request processing template
- Response processing template
Currently, the XML processing templates borrow the custom deliverable template system, accessible under Settings > Deliverables > Mass Deliverables > Custom Deliverables. All templates are processed with Jinja2 template engine.
2.1 Configure Router Template
The router template must be named “acord_xml_router”, and construct a JSON object with the following attributes:
- api: Specify which API endpoint to invoke, in dot format. Example: api.v2.policies.create_quote_extended will send the processed request to /api/v2/policies/create_quote_extended endpoint.
- request_template: Specify the template name to transform the request XML content to API JSON input. See section 2.2.
- response_template: Specify the template name to transform the API JSON output to response XML content. See section 2.3.
The router template can send the request to different processing paths, based on request XML content. Here is an example that supports EZLynx’s credential test on top of the rating request:
{%- set acord = document -%} {%- if acord.xpath('*')|length == 1 and acord.SignonRq -%} { "api": "api.v2.contacts.get_contact", "request_template": "acord-signon-verify-rq", "response_template": "acord-signon-verify-rs" } {%- else -%} { "api": "api.v2.policies.create_quote_extended", "request_template": "acord-home-policy-rq", "response_template": "acord-home-policy-rs" } {%- endif -%} |
The XML content is available under the “document” global symbol, provided by lxml.objectify API (see lxml docs). It provides flexible access to the document content, including XPath as shown above.
2.2 Configure Request Template
The request template has the same “document” global symbol to read into request XML content.
Based on the API endpoint the router template selects, the request template needs to construct a JSON object to pass into the API endpoint. Look up https://api.britecore.com/ for the specific API endpoint.
The request template has two additional facilities for assisting the processing:
- “var_data” global: “var_data” is initialized as an empty Python dictionary. The request template can add any keys and values, and pass them to the response template. You can store intermediate processing results to share with the response template processing.
- “raise_hard_stop()” call: using it in the request template will skip the call to the API endpoint. This is particularly useful when a hard-stop condition is detected (for example, certain combinations disallowed from comp rater quoting). The processing will directly go into the response template, with any “var_data” keys and values that are set before raising the hard stop.
Additionally, look up Appendix A for supported utility functions as global symbols for template processing.
Here’s an example request template that maps an ACORD XML input to a valid input to create_quote_extended API endpoint: Request Template Example
2.3 Configure Response Template
Response template constructs an XML response based on the request XML content and the API response.
The following globals are available:
- “document”: Same as router and request templates.
- “api_response”: The dictionary object returned by the API endpoint. (If the request template has called “raise_hard_stop()”, this will be None.)
- “var_data”: any data passed from the request template.
To construct the XML response, you may alter the “document” in place using Appendix A. Utility Functions, and then use the “to_xml()” function to serialize the document object.
Here is an example response template that works with the previous request template example: Response Template Example
Appendix A. Utility Functions
XML Document Manipulation
- add_sub_tag(el, tag_name, tag_ref=None, tag_value=None): Adds a child tag to an existing XML element. “tag_ref” attaches a “Ref=” attribute; “tag_value” sets its text content.
- change_tag(el, old_tag_name, new_tag_name): Changes the name of an existing tag.
- change_value(el, child_tag_name, value): Rewrites the value of a child tag.
- new_element(tag_name, tag_ref=None): Creates a new XML element. “tag_ref” attaches a “Ref=” attribute.
- add_new_element(parent_el, el): Adds a new element as a child to the parent element.
- delete_tag(parent_el, tag): Deletes a tag from the parent element.
- remove_element(el): Removes the element from the XML document.
- to_xml(document_el): Renders an XML document to a string.
Other Utility Functions
- parse_date(date_string): Reads a date string into a Python date object.
raise_hard_stop(message=””): Raises a hard stop.