Working with Ultra Input/Output Headers, Content, Parameters, and Status Codes
For ultra, this is all you need to work with headers, content, and url parameters. Accessing a URL parameter from an Input request. All url parameters passed on the call in must be accessed in the incoming document and not like a traditional trigger. _paramName does not work. All URL parameters will come in the “query” object of the input document and each distinct parameter will be represented by an array of the values passed in to those parameters. Most cases you’re only sending one value into one parameter so here in the SS I’m using the first array element 0. Content and headers are easier. Your input document you access all incoming headers from the root, and all content from an object named “content”. Ignore the fact that I’m writing everything to content on the right side, that’s just something I’m doing in the pipeline. Please also note that ALL input headers will be cast to lowercase, even if they are sent in as uppercase. Your mapping must reflect this else you’ll have problems reading the headers. Writing out responses is almost exactly the inverse. Minus the addition of status, body content back to the caller is inside of content. Headers are in root, you can send back custom headers. Status code is in a field called “status”3KViews3likes0CommentsCapture runtime document in ultra pipeline for debugging purpose
Sometimes you want to capture input or output document of snaps at runtime in ultra pipeline for debugging purpose. Here’s a quick way: Don’t use File Writer Snap as it break the lineage in ultra pipeline Use a Pipeline Execute Snap Send the logging content as one or multiple parameter to the child pipeline Make sure the child pipeline do nothing heavy weight Make sure set the child pipeline capture the parameter in question View the captured parameter in Dashboard You can copy the captured parameter and paste it to a JSON pretty print tool for better viewing5.7KViews3likes5CommentsCreating APIs with SnapLogic Pipelines and Ultra Tasks
Overview API (Application Program Interface) is an old concept repurposed to mean a modern web service based on the REST protocol and increasingly using the JSON data format. These modern APIs have become the franca lingua of the digital economy, by facilitating lightweight, performant communication between applications across an enterprise or across the internet. Typically RESTful APIs perform operations on “resources” (Customers, Orders, People, etc). By convention, the type of operation is identified using the most common HTTP verbs such as POST (create), GET (read), PUT (update), DELETE SnapLogic provides Ultra Tasks as the means by which a Pipeline can be exposed as a secure, high-availability, low-latency, sub-second request/response API. For example, the following is a Pipeline that embodies a Customer API exposed using an Ultra Task: Once the Ultra Task is enabled, the associated Pipeline stays resident in memory on the Snaplex node(s) it was configured to execute on. The number or Instances can be configured to accomodate the expected concurrent API request volume. The API can then be called securely from an external application (Postman REST client in this case): This is an example of an API GET (read) request for a specific Customer identified by the ID “1001” Designing the Pipeline Ultra Tasks deliver the components of the HTTP request message to its associated Pipeline as fields in the JSON document: content: The request body for POST or PUT requests headers: For example, the ‘User-Agent’ HTTP header can be referenced in the input document as $[‘user-agent’] uri: The original URI of the request. method: The HTTP request method. query: The parsed version of the query string. The value of this field will be an object whose fields correspond to query string parameters and a list of all the values for that parameter. For example, the following query string: foo=bar&foo=baz&one=1 Will result in a query object that looks like: { "foo" : ["bar", "baz"], "one": ["1"] } task_name: The name of the Ultra task. path_info: The part of the path after the Ultra task URL. server_ip: The IP address of the feed-master that received the request. server_port: The TCP port of the feed-master that received the request. client_ip: The IP address of the client that sent the request. client_port: The TCP port of the client that sent the request. In the above Customer API example: A Mapper Snap is used to parse the ID from the portion of the URL after the base path provided by the Ultra Task (demo-fm.snaplogic.io/api/1/rest/feed-master/queue/MyOrg/MyProjectSpace/API/Customers)… In this case “/1001”: A Router Snap is used to conditionally direct execution to the appropriate subflows designed in accordance with the RESTful CRUD operations described above: Additional Reference https://en.wikipedia.org/wiki/Representational_state_transfer http://doc.snaplogic.com/ultra-tasks13KViews1like5CommentsScript snap with ultra pipelines: original property mapping to doc which is modified
Hi, I have a question regarding this statement from the SnapLogic documentation on Ultra Pipeline tasks (https://docs-snaplogic.atlassian.net/wiki/display/SD/Ultra+Pipeline+Tasks): Script and Execute Script Snaps need you to pass the original document to the ‘write()’ method for the output view. I am using a script snap in a pipeline to modify the original document to move some properties around (thereby changing the original document). I am wrapping my original document in a wrapper and putting it in the original property as demonstrated in the sample Script snap. However, “original” contains my modified doc. Will this be a problem if I try to use Ultra? A snippet from my Script snap is included below: execute : function () { this.log.info("Executing Transform Script"); while (this.input.hasNext()) { try{ // Read the next document, wrap it in a map and write out the wrapper var doc = this.input.next(); var wrapper = new java.util.HashMap(); wrapper.put("original", doc.clone()); wrapper.put("integrationMessage", doc["integrationMessage"]); var studentGradesWrapper = doc["integrationMessage"]["body"]["gradingSheetInfo"]["gradingSheet"]["studentGrades"]; var supplementalInfosWrapper = doc["integrationMessage"]["body"]["gradingSheetInfo"]["supplementalInfos"]; ensureArray(studentGradesWrapper,"studentGrade"); ensureArray(supplementalInfosWrapper, "supplementalInfo"); var studentIdsToCslwIdsMap = new java.util.HashMap(); supplementalInfosWrapper["supplementalInfo"].forEach( function(supplementalInfo) { studentIdsToCslwIdsMap.put(supplementalInfo["studentId"], supplementalInfo["coursesectionLW"]["objectId"]); } ); studentGradesWrapper["studentGrade"].forEach( function(studentGrade) { studentGrade.put("snapLogicCourseSectionLWId",studentIdsToCslwIdsMap.get(studentGrade["student"]["objectId"])); } ); this.output.write(doc, wrapper); } catch(err) { var wrapper = new java.util.HashMap(); wrapper.put("errorMsg", err); this.log.error(err); this.error.write(wrapper); } } }2.7KViews1like1Comment