Some applications accept only XML. To send records to one from an HTTP import, you write the XML in the HTTP request body of the import and use handlebars expressions to fill in values from each record and from the connection. This example is for builders who import into an XML API. It builds the request body that sends Jira Cloud issues to OpenAir as project tasks, which is what the OpenAir – Jira Cloud platform template does.
Parts of the request
Before you write the request body, find three things in the XML API documentation of the destination application. For OpenAir, all three are in the OpenAir XML API guide.
-
Request element — The XML declaration and the element that wraps every request. In OpenAir, the
requestelement carries the API version, the client name, your namespace, and your API key. -
Authentication — The element that signs you in. In OpenAir, the
Authelement holds a company, a user, and a password. -
Record element — The element for the record you send, and its fields. This example modifies a
Projecttask.
Copy the element and attribute names for your application from its API documentation. The names in this example are the ones that the OpenAir request uses.
Build the request body
- Go to Home
, open the integration, and then open the flow.
- Select the HTTP import step.
- In HTTP request body, paste the sample request from the API documentation: the request element, then the authentication, then the record element.
- Replace each value with a handlebars expression.
- Select Preview to check the request against a sample record.
For the editor and the values that an expression can use, see Build HTTP request body and Relative URI.
After step 3, the request body holds the structure of the request with no values.
<?xml version="1.0" encoding="UTF-8"?>
<request API_ver="1.0" client="integrator.io" namespace="" key="">
<Auth>
<Login>
<company></company>
<user></user>
<password></password>
</Login>
</Auth>
<Modify type="Projecttask" enable_custom="1">
<Projecttask>
<name></name>
<id></id>
<customerid></customerid>
<userid></userid>
<Jira_Issues_ID__c></Jira_Issues_ID__c>
<projectid></projectid>
</Projecttask>
</Modify>
</request>After step 4, every value comes from the connection or from the record.
<?xml version="1.0" encoding="UTF-8"?>
<request API_ver="1.0" client="integrator.io" namespace="{{connection.http.unencrypted.namespace}}" key="{{connection.http.unencrypted.apiKey}}">
<Auth>
<Login>
<company>{{{connection.http.unencrypted.companyId}}}</company>
<user>{{{connection.http.unencrypted.userId}}}</user>
<password>{{{connection.http.encrypted.password}}}</password>
</Login>
</Auth>
{{#each data}}
{{#if Jira_Issues_ID__c}}
<Modify type="Projecttask" enable_custom="1">
<Projecttask>
<name>{{fields.summary}}</name>
<id>{{customfield_10030}}</id>
<customerid>{{lookup "customerIdLookup" fields.project.id}}</customerid>
<userid>{{fields.assignee.key}}</userid>
<Jira_Issues_ID__c>{{id}}</Jira_Issues_ID__c>
<projectid>{{lookup "projectIdLookup" fields.project.id}}</projectid>
</Projecttask>
</Modify>
{{/if}}
{{/each}}
</request>Every element and every handlebars block that the template opens is also closed. A request body that leaves one open isn't valid XML.
Expressions in the template
Each kind of expression in the finished template does a different job.
-
Connection values —
{{connection.http.unencrypted.namespace}}and the otherconnectionexpressions read values stored on the connection, so the request body holds no credentials. -
Triple braces —
{{{ }}}writes a value as is. Double braces escape special characters, which keeps the XML valid when a value contains a character such as&. -
Loop —
{{#each data}}repeats theModifyelement once for each record in the request. -
Condition —
{{#if Jira_Issues_ID__c}}writes the element only for a record that has a value inJira_Issues_ID__c. -
Record values —
{{fields.summary}}and{{id}}read fields from the Jira issue. -
Lookups —
{{lookup "customerIdLookup" fields.project.id}}replaces the Jira project ID with the matching OpenAir ID from a lookup defined on the import. See Add a lookup to an import mapping.