Use Case - Looking Up Phone Numbers via Search.ch API

Submit an API request to search.ch in order to look up unknown phone numbers.

Local.ch and search.ch are services of the Swisscom Directories (https://www.localsearch.ch/). The platform’s core product is basically Switzerland’s phone directory and services range from presence & marketing services to online service tools (such as online booking & reservation, online payment, website builder, comparison platform.) search.ch provides contact information in form of a classical phone book directory. One can use their API to query the directory.

As of  the terms of service state: “The monthly usage quota per customer and API-Key is 1000 requests. A maximum of 20 results are provided per request.” Therefore, we can freely use the API, but should try to limit the requests, e.g., by storing the returned results in our internal CRM or another database to avoid re-querying the API each time. Storage is allowed, but we need to comply to the terms of use (“Permitted types of use"). When storing information, source reference must be provided with all forms of API usage: “Swisscom Directories AG“.


☝ Please note that the terms of use can change any time! Before implementing this flow, please check https://search.ch/tel/api/terms

 

PRECONDITIONS

  • search.ch API key. You can request a key at https://tel.search.ch/api/getkey 
    🔍 Note that keys might be limited to one per company.
  • Power Automate Premium license (required to make use of the HTTP request action)
  • (Optional) A CRM or other database for caching the returned data
 

How-To: Look Up Phone Numbers

Create a new flow

  1. Sign in to Power Automate.
  2. Go to “My Flows".
  3. Click "+ New Flow" and create a blank "Automated Cloud Flow".
  4. Give your new flow a meaningful name, e.g., "Look Up Phone Number via search.ch".
  5. In the text box underneath, search for "Nimbus" and choose the "When a task changes state" trigger.
  6. Click the "Create" button.

Configure the trigger

In our example, we want the new flow to react specifically to new inbound audio calls toward one of our services.

  1. Select the "When a task changes state" trigger.
  2. In the "Services" dropdown select the Nimbus service's UPN.
    💡 You can also get the data of multiple services at this point, but for the sake of simplicity we keep it to one service in this example.
  3. In the "Task Events" dropdown select "System Accepted".
  4. In the "Advanced parameters" dropdown enable "Modalities" and "Directions".
  5. In the "Modalities" dropdown select "Audio".
  6. In the "Directions" dropdown select "Inbound".

Optional: First internal CRM check

To avoid overusing the search.ch API, we can first check whether the caller information is already stored in our internal CRM or other database.

💡 You can find an example of how to query an external data source in Use Case - Looking Up Caller Data from a Simple Excel List and adapt it to your needs.

If this check already returned any results, you can immediately execute the "Update task" action (see further below for an example) and skip any subsequent queries against the search.ch API. This can be accomplished by first using a "Condition" action, which checks whether the CRM lookup returned data.

💡In the above example, we are first querying a SharePoint list for the caller's telephone number and then check whether the returned array is empty. If True, we can proceed with the search.ch API query (see below steps). If False, we can use the cached data to update Nimbus immediately.

Query the API

If the first CRM lookup came up empty, we can proceed with the search.ch API query.

  1. Click on and select "Add an action"
  2. Search for and select the "HTTP" action
  3. Fill in the details
Field Value
URI https://tel.search.ch/api/
Method GET
Headers content-type text/xml; charset=utf-8
vary Accept-Encoding
Queries key <Your search.ch API key>
q Caller Telephone Number (data dynamically provided by trigger event)

Parse the response data

If successful, the query response will be provided in XML format, which we now need to parse for the desired information. In the example below, we will first check whether any records were returned at all.

💡 You can find an example of an XML response at https://search.ch/tel/examples/api-response.xml. The response format is further explained at https://search.ch/tel/api/help#response.

Show an example Luware response…

<?xml version="1.0" encoding="utf-8" ?>
                                <feed xml:lang="de" xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:tel="http://tel.search.ch/api/spec/result/1.0/">
                                 <id>https://tel.search.ch/api/d89734ad31b70f1f7487ce6630088d3c/dadc4ed1ae337c00ef6cbb4a6d6afd38</id>
                                 <title type="text">tel.search.ch API Search Results</title>
                                 <generator version="1.0" uri="https://tel.search.ch">tel.search.ch</generator>
                                 <updated>2022-03-03T13:16:49+01:00</updated>
                                 <link href="https://tel.search.ch/result?was=05840428" rel="alternate" type="text/html" />
                                 <link href="http://tel.search.ch/api/?was=+41+58+404+28&key=redacted" type="application/atom+xml" rel="self" />
                                 <openSearch:totalResults>1</openSearch:totalResults>
                                 <openSearch:startIndex>1</openSearch:startIndex>
                                 <openSearch:itemsPerPage>10</openSearch:itemsPerPage>
                                 <openSearch:Query role="request" searchTerms="05840428 " startPage="1"></openSearch:Query>
                                 <openSearch:Image height="1" width="1" type="image/gif">https://www.search.ch/audit/CP/tel/de/api</openSearch:Image>
                                 <entry>
                                 <id>urn:uuid:107b409c0e772820</id>
                                 <updated>2020-12-15T17:54:42+01:00</updated>
                                 <published>2020-12-15T17:54:42+01:00</published>
                                 <title type="text">Luware AG</title>
                                 <content type="text">Luware AG
                                 Pfingstweidstrasse 102
                                 8005 Zürich ZH
                                 *058 404 28 00</content>
                                 <tel:nopromo>*</tel:nopromo>
                                 <author>
                                 <name>tel.search.ch</name>
                                 </author>
                                 <link href="https://tel.search.ch/zuerich/hardturmstrasse-127/luware-ag" title="Details" rel="alternate" type="text/html" />
                                 <link href="https://tel.search.ch/vcard/Luware-AG.vcf?key=107b409c0e772820" type="text/x-vcard" title="VCard Download" rel="alternate" />
                                 <link href="https://tel.search.ch/edit/?id=107b409c0e772820" rel="edit" type="text/html" />
                                 <tel:pos>1</tel:pos>
                                 <tel:id>107b409c0e772820</tel:id>
                                 <tel:type>Organisation</tel:type>
                                 <tel:name>Luware AG</tel:name>
                                 <tel:street>Hardturmstrasse</tel:street>
                                 <tel:streetno>127</tel:streetno>
                                 <tel:zip>8005</tel:zip>
                                 <tel:city>Zürich</tel:city>
                                 <tel:canton>ZH</tel:canton>
                                 <tel:country>ch</tel:country>
                                 <tel:phone>+41584042800</tel:phone>
                                 <tel:copyright>Daten: Swisscom Directories AG</tel:copyright>
                                 </entry>
                                </feed> 
 
 
  1. Click and select "Add an action".
  2. Search for and select the "Condition" action.
  3. Click into the "Choose a value" input field and select "Insert Expression".
  4. Use the following expression to extract the totalResults value from the API response.
    🔍 If you renamed your HTTP action in the previous step to something different, you will need to update the name in the expression as well.
int(xpath(xml(body('HTTP')), '//*[name()="openSearch:totalResults"][1]/text()')[0])
  1. Configure the rest of the expression to check whether the totalResults value retrieved by this expression is greater than zero. If yes, we can proceed with extracting more data and updating the Nimbus task. If not, we do nothing and let the flow end.

💡 To extract more data from the response, you can use variations of the below XPath expression, which you can build and test with a tool like http://xpather.com/.

xpath(xml(body('HTTP')), '<Insert XPath query here>')

Some examples to get data from the response XML

XPath query

Matches

Output from example XML

//*[name()="tel:name"][1]/text() tel:name node Luware AG
normalize-space(//*[name()="content"][1]/text()) content node text without line breaks Luware AG Pfingstweidstrasse 102 8005 Zürich ZH *058 404 28 00
//*[name()="tel:type"][1]/text() tel:type node
(value is either “Organisation” or “Person”)
Organisation
//*[name()="tel:copyright"][1]/text() tel:copyright node
(must be included if data is stored elsewhere)
Daten: Swisscom Directories AG
 
 

Update the Nimbus task

We can now proceed to update the Nimbus task.

  1. Click on and select "Add an action".
  2. Search for and select the "Update task" action from the “Luware Nimbus” connector.
  3. In the "Task ID" field, select the "Task ID" value dynamically provided by the flow's original trigger event.
  4. Under "Advanced Parameters", select the parameters that you wish to update for the task.
  5. For each parameter, fill in the corresponding expression, variable, or other output from your previous flow actions.

Optional: Store the response data in your CRM

Using the same logic as in the step above, we can now also store the retrieved data in our CRM or other database, to avoid having to query the search.ch API once more if the same caller contacts us again.

In the example above, we are simply adding another step that adds a new entry to a SharePoint list after the Nimbus task has been updated.

💡 You can also execute the corresponding flow actions in a parallel branch to save time.

Table of Contents