Supplementing data with call to REST api

Hi,

Is it possible to call an external REST api from datamapper to supplement data? What I want to do is call the api of a service that we have that creates shipping data and shipping label content. I then want to add some of the fields in the response to the data mapping so that I can use them as fields in the template. The call will contain data from the input file.

I was thinking of using JavaScript XHR so create the json for the call and to make the call with XMLHttpRequest. Would that work, where/how would be a good way to run the js? Any special considerations when doing so?

Thanks,
Fredrik

1 Like

Since Connect 1.7, the DataMapper’s Scripting API provides you with the createHTTPRequest() method, which returns an XHR object. You can use that object in a Script Step and store the values you retrieve from your service in a JSON object, for instance, that you then store in a record variable. You can then extract those values from the record variable anywhere in the DM process after that script.

More info: PlanetPress Connect 2018.1 User Guide

1 Like

Thanks, that should do the trick. Sorry for not finding it in the help myself. (Not sure how I missed it.)