Update Customer Model fields using Web Services

Last updated:

If you need to keep your client data up to date using results from SOAP or REST services, Prisma Campaigns provides the means to do so. This article explains how to update model fields via a web service, using its response either in JSON or XML format. It is important to note that the concepts detailed below apply to the client model at both the global and campaign level, but the value obtained must be consistent with the data type.

Indicating Fields to Be Updated

To begin, you need to set the fields to update in the campaign funnel. To do this, follow these steps:

  1. Add a new web service step in the funnel.
  2. Enter a description and the address of the corresponding web service.
  3. Check the Update fields with response checkbox.
  4. In the Update tab, add the number of fields you want to update by clicking the Add field to update button.
  5. Select the corresponding field for each case. For the time being, leave the associated expressions blank.

The following image shows a funnel step with the description Update customer that uses the response from the address https://api.bankofholland.com/get-customer to update phone and owns_home:

In the next section, we will add the necessary expressions to extract the desired values from the results the web service provides.

Adding Expressions

Because the response from the web service is expected to have a complex structure (JSON or XML), we use expressions against the complete result to select the values of interest. In either case, there are 3 functions to perform this task (node-exists, node-count and node-value) using the appropriate selectors as detailed below.

JSON

We will use as an example the following response in JSON format to illustrate the use of expressions to extract values:

{
  "documentTypes": [
    {
      "documentTypeDescription": "RUT",
      "documentTypeId": 1
    },
    {
      "documentTypeDescription": "CÉDULA DE IDENTIDAD",
      "documentTypeId": 3
    },
    {
      "documentTypeDescription": "PASAPORTE",
      "documentTypeId": 10
    }
  ],
  "operationResult": {
    "value": "0",
    "valueName": "success",
    "isEnum": "true"
  }
}

The functions json-node-exists, json-node-count and json-node-value perform the parametrized selection using the syntax defined by the JSON PATH project. For example:

Expression Result
json-node-value("$.operationResult.value") 0
json-node-exists("$.documentTypes") true
json-node-exists("$.documentTypeId") false
json-node-exists("$..documentTypeId") true (This field is present at the second level)
json-node-value("$..documentTypeId") 1 (first value found that matches the selector)
json-node-count("$..documentTypeId") 3 (examines the second level and returns the number of objects that match the given selector)
json-node-count("$.documentTypeId") 0
json-node-value("$.documentTypes[1].documentTypeId") 3 (value present at index 1 in the collection)
json-node-value("$.documentTypes[7].documentTypeId") nil

Following the same pattern, let us suppose the web service you are utilizing returns this response:

{
  "phone": "+5491156898754",
  "owns_home": "No"
}

As the next step, add the necessary expressions to update the fields phone and owns_home:

json-node-value("$.phone")
json-node-value("$.owns_home")

Last, save the changes by clicking on Update.

XML

Instead of JSON, the expected response can be in XML format like the following. In that case, we will use the selectors indicated according to the degree of complexity and the value we need to select. The syntax to be used is detailed here.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aut="http://www.bankofholland.com/middleware.services/authType" xmlns:con="http://www.bankofholland.com/middleware.services/queryClientTypes">
   <soapenv:Header>
      <aut:RequestHeader>
         <Authentication>
            <UserName>bankofholland</UserName>
            <Password>Holland202i$</Password>
         </Authentication>
         <Region>
            <SourceBank>HN01</SourceBank>
            <!--Optional:-->
            <DestinationBank></DestinationBank>
         </Region>
      </aut:RequestHeader>
   </soapenv:Header>
 <soapenv:Body>
      <con:queryClientRequest>
         <con:CUSTOMER_ID_TYPE>CUSTOMER_ID</con:CUSTOMER_ID_TYPE>
         <con:CUSTOMER_ID_VALUE>123654</con:CUSTOMER_ID_VALUE>
      </con:queryClientRequest>
     <con:queryClientRequest>
         <con:CUSTOMER_ID_TYPE>CUSTOMER_ID</con:CUSTOMER_ID_TYPE>
         <con:CUSTOMER_ID_VALUE>789654</con:CUSTOMER_ID_VALUE>
      </con:queryClientRequest>
   </soapenv:Body>
</soapenv:Envelope>

For example:

  • xml-node-value("[:Password]") will return Holland202i$.
  • xml-node-exists("[:Region [:SourceBank]]") equals true.
  • xml-node-count("[:con:queryClientRequest]") will be 2.

On the other hand, if we have this XML:

<con:PHONE_INFO>
  <con:PHONE_NUMBER_ITEM>
    <con:PHONE_TYPE>PHONE</con:PHONE_TYPE>
    <con:PHONE_NUMBER>50422396410</con:PHONE_NUMBER>
    <con:PHONE_ORDER>1</con:PHONE_ORDER>
    <con:PHONE_EXTENSION />
    <con:PHONE_REFERRENCE>WORK</con:PHONE_REFERRENCE>
  </con:PHONE_NUMBER_ITEM>
  <con:PHONE_NUMBER_ITEM>
    <con:PHONE_TYPE>PHONE</con:PHONE_TYPE>
    <con:PHONE_NUMBER>50427663456</con:PHONE_NUMBER>
    <con:PHONE_ORDER>2</con:PHONE_ORDER>
    <con:PHONE_EXTENSION />
    <con:PHONE_REFERRENCE />
  </con:PHONE_NUMBER_ITEM>
  <con:PHONE_NUMBER_ITEM>
    <con:PHONE_TYPE>SMS</con:PHONE_TYPE>
    <con:PHONE_NUMBER>50499906860</con:PHONE_NUMBER>
    <con:PHONE_ORDER>3</con:PHONE_ORDER>
    <con:PHONE_EXTENSION />
    <con:PHONE_REFERRENCE>WORK</con:PHONE_REFERRENCE>
  </con:PHONE_NUMBER_ITEM>
</con:PHONE_INFO>

we can perform the following extraction:

Get the value of the :con:PHONE_NUMBER node that is a child of :con:PHONE_INFO and :con:PHONE_NUMBER_ITEM, which contains a child node with the value SMS and another one with the value 3:

xml-node-value("[:con:PHONE_INFO [:con:PHONE_NUMBER_ITEM [(net.cgrand.enlive-html/has [(net.cgrand.enlive-html/text-pred #(= \"SMS\" %))])] [(net.cgrand.enlive-html/has [(net.cgrand.enlive-html/text-pred #(= \"1\" %))])]] [:con:PHONE_NUMBER]]")

Under this scenario, the value returned by the selector will be 50499906860.