Overview
Fetches JSON data from an external REST API using pfx-rest:get and loads it into Pricefx using pfx-api:loaddata. Uses an OAuth2 connection for authentication.
Prerequisites
Define the REST connection in connections/external-api.json (see Connection Examples > OAuth2 REST Connection Setup).
Mapper: mappers/product-api-mapper.xml
<mappers>
<loadMapper id="productApiMapper">
<body in="productCode" out="sku"/>
<body in="productName" out="label"/>
<body in="currencyCode" out="currency"/>
<groovy expression="body.unitPrice?.toBigDecimal()" out="attribute1"/>
<constant expression="ACTIVE" out="attribute2"/>
</loadMapper>
</mappers>
Route: routes/import-from-rest.xml
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="importProductsFromApi">
<from uri="scheduler://apiImport?delay={{api.poll.interval.ms}}"/>
<to uri="pfx-rest:get?uri=/v1/products&connection=externalApi"/>
<!-- REST response body is a JSON array — convert to List of Maps -->
<unmarshal>
<json library="Jackson" useList="true"/>
</unmarshal>
<to uri="pfx-api:loaddata?objectType=P&mapper=productApiMapper"/>
<onCompletion onCompleteOnly="true">
<to uri="pfx-api:internalCopy?label=Product"/>
</onCompletion>
</route>
</routes>
Properties:
api.poll.interval.ms=3600000
How It Works
-
pfx-rest:getcallsGET /v1/productson theexternalApiconnection -
The response body is a JSON string —
unmarshalwithuseList=trueconverts it toList<Map> -
pfx-api:loaddatasends rows to Pricefx using the mapper -
pfx-api:internalCopypublishes the loaded data to make it visible in Pricefx
Common Pitfalls
-
pfx-rest:getreturns the raw response body as a String — always unmarshal JSON before passing topfx-api:loaddata -
Use
useList=truein Jackson unmarshal when the response is a JSON array -
If the API returns
{"items": [...]}(wrapped object), extract with<setBody><simple>${body[items]}</simple></setBody>before loaddata