# Configuration examples (REST)

## Example 1: Weather Web Service Configuration

This section describes the steps to configure a REST weather web service to automatically respond to user requests. You can use the openweathermap service (<https://openweathermap.org/api>) for this purpose. **You will need to create an account to obtain an API key.**

To carry out this configuration, you must perform the following steps:

### Creating and configuring a web service

1 - Go to **Contents > Web Services**.

2 - Click on **Add** and then select **Rest Web Service**.

<figure><img src="/files/SLCJUi4delxroIdbxYzs" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/02I0vTsDC0zCYkzxufJF" alt=""><figcaption></figcaption></figure>

3 - Fill in the following fields in "Web Service Configuration".

* Name : "Meteo"
* URL : "<http://api.openweathermap.org/data/2.5/weather>"
* HTTP Method : GET
* Type de réponse : JSON

<figure><img src="/files/JuUobB2Szzl1YXB31tjo" alt=""><figcaption></figcaption></figure>

4 - Fill in the following fields in "Parameters".

* APPID: The parameter is provided by WorldWeatherOnline after creating an account.
* lang: fr
* q: ${capture.ville meteo}

<figure><img src="/files/W9BdtXYdbdzPCbdneM7J" alt=""><figcaption></figcaption></figure>

5 - Click on "Add" in the "Result Variables" category and add the following two variables:

<figure><img src="/files/Q5FujyuRC6tq7KAb0nf8" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
Attention: variable names are free to choose but must be consistent with what is indicated in the knowledge. Variable names must consist of alphanumeric characters or underscore characters and start with a letter. They are also case-sensitive.
{% endhint %}

6 - Change the JSON output format with the following values:

```
function dyduParseJSON(json) {
 // returns a map return {
     "name" : json.name, 
     "description" : json.weather[0].description, 
     "temperature" : parseInt(json.main.temp / 10)
      } 
      }
```

<figure><img src="/files/K2nNI7fCiSXmgbRtcOdH" alt=""><figcaption></figcaption></figure>

7 - Test the configuration of your web service.

<figure><img src="/files/QqluPisW7gFihM53yaQ1" alt=""><figcaption></figcaption></figure>

with the test value 'Paris' in the parameters:

<figure><img src="/files/VBlZHrV6Uw9REFG5CUs7" alt=""><figcaption></figcaption></figure>

### Creation of the associated knowledge

The objective now is to create knowledge to provide data to the web service and deliver it to users.

#### Configure the query:

**User's phrase :** The sentence should resemble a request to know the weather in a given city. The crucial point in this sentence is not to forget the variable. In our example, the variable is called "**ville"** and it is **Alphanumeric** type.

1 - Create a knowledge "What is the weather in" and then click on "T".

<figure><img src="/files/kjCjp0J1dbJviY6pn76A" alt="" width="237"><figcaption></figcaption></figure>

2 - Search for the variable "Ville"

<figure><img src="/files/y89sLpb5R00WkMRBVu8c" alt="" width="274"><figcaption></figcaption></figure>

3 - Click on the city group and name the variable "villemeteo"

4 - Click on "**update**"

<figure><img src="/files/yDEiwszpbBjyGut937ah" alt="" width="327"><figcaption></figcaption></figure>

5 - Click on "**Create**" to create the knowledge

<figure><img src="/files/x83Byt7hS9b4z9SpCE2H" alt="" width="375"><figcaption></figcaption></figure>

#### Configure the response

The response given to the user will display the temperature and the city understood by the system to identify any discrepancies.

<figure><img src="/files/UOBIz0JEwJllIYt5JHwE" alt="" width="353"><figcaption></figcaption></figure>

{% hint style="info" %}
It is important to note that:

* Variables retrieved from the web service are structured as follows: ${callapi.WebServiceName.variableName}
* Variables retrieved from the dialogue box are structured as follows: ${capture.VariableName}
  {% endhint %}

For more detail :

{% embed url="<https://youtu.be/O5V8kwSW4_U>" %}

## Example 2: Use the web service in a condition

Web services can be used in knowledge but also in conditions. Reuse the weather service to find out if it's hot or cold in a city. In our example, it is considered that it is hot at more than 20 degrees and cold in the opposite case.

1 - Create a new knowledge to answer.

<figure><img src="/files/HXc3unJVT394ReRiVKl8" alt=""><figcaption></figcaption></figure>

2 - Then create the two possible answer with a new condition that you leave blank for now:

<figure><img src="/files/40kU0R0L2ZmisjPFM9sd" alt="" width="340"><figcaption></figcaption></figure>

Once the knowledge part is prepared, you have to create a new condition that will use the web service. To do so, visit the **Knowledge > Advanced > Context conditions** page.

1 - Click **Add a condition** and create the associated condition:

<figure><img src="/files/ABtVNU7qlEuEdYoK7cSE" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Note that the operation is of **Math expression** type and the value must be a correct expression with **x** the variable returned by the expression in **Condition**. Here, we must check that **callapi.TestWeather.Temperture > 20**.
{% endhint %}

Finally, we must use this new condition in the knowledge we have created. To do so:

1 - Edit the condition, select **IsTempertureGreaterThan20**

2 - Click **Update**.

<figure><img src="/files/u9QlFAnYy7Liji7z3v0E" alt="" width="344"><figcaption></figcaption></figure>

You can now test your knowledge with the bot.

## Example 3: Web service configuration - IP address

Here we will use the httpbin web services: <http://httpbin.org/> and specifically the IP web service that returns the IP of the requesting user.

### Creation and configuration of the web service

1 - Create a web service in REST mode.

<figure><img src="/files/yIO1FR3vG9w6r1ymJVbo" alt=""><figcaption></figcaption></figure>

2 - Enter the JSON code in the **Result Variables** section :&#x20;

```
function dyduParseJSON(json) {
	 return {'ip' : json.origin};
}
```

3 - Enter the variable "IP" by clicking on "add". You can add as many variables as you want.

<figure><img src="/files/gomlEMzuzoPPimrE3DMB" alt=""><figcaption></figcaption></figure>

4 - Then click on **Save**.

5 - Click the **Test** button to verify that the web service is operational.

<figure><img src="/files/ZyQ3cVkczATmjWn9ka52" alt="" width="262"><figcaption></figcaption></figure>

If there are no errors, the IP will be returned to you; otherwise, an ERROR element may appear. It's important to note that HTTPS web services may not work. If that's the case, simply remove the "S" to use HTTP protocol only.

### Creation of the associated knowledge

Next, go to the **Content > Knowledge** page and create a new knowledge entry like the example below:

<figure><img src="/files/DM6GY9LQtIdbhKUwLSIy" alt="" width="274"><figcaption></figcaption></figure>

You can then test your knowledge by asking your bot through the test dialogue box. Ask it the question "What is my IP?" and the bot will return your IP address.

<figure><img src="/files/iD3qbumFmteze7DyK95E" alt="" width="268"><figcaption></figcaption></figure>

## Example 4: Sending multiple attachments

For example, if your bot offers to create an IT support ticket, you can allow the user to add one or more attachments during the ticket creation process.

There are two different ways to configure your webservice for sending multiple attachments:

### Configuration via the request Body (JSON Format)&#x20;

In the Body of your POST request, use the `${DialogAllLastFilesUploaded()}` function. The three parameters you pass in parentheses define the key names that will appear in the final JSON.

* Parameter 1: Key name for the file name.
* Parameter 2: Key name for the content type.
* Parameter 3: Key name for the base64 content.

Example of your Web Service Body:

```
{
  "summary": "Nouveau ticket",
  "project": {
    "id": "81-276"
  },
  "files": ${DialogAllLastFilesUploaded("fileName", "fileContentType", "base64Data")}
}
```

At runtime, the engine replaces the variable with an array of objects. Here is what the JSON stream sent to your server looks like if the user uploaded two files:&#x20;

```
{
  "summary": "New ticket",
  "project": {
    "id": "81-276"
  },
  "files": [
    {
      "fileName": "File1.txt",
      "fileContentType": "text/plain; charset=UTF-8",
      "base64Data": "VGVzdAo="
    },
    {
      "fileName": "File2.txt",
      "fileContentType": "text/plain; charset=UTF-8",
      "base64Data": "VGVzdDIK"
    }
  ]
}
```

### Configuration via a parameter (Multipart Format)&#x20;

This second approach is ideal if the destination server expects a request in standard file upload format (multipart/form-data) rather than a JSON stream. It has the advantage of being automatically generated by the system.

How to configure this method? Instead of manually building the Body of your request, simply use the function directly in your Web Service parameters.

* The function to use: Simply enter `${DialogAllLastFilesUploaded()}`.
* Please note: Unlike the Body method, the parentheses must remain empty. It is not necessary to define key names.

What happens during execution? The tool takes over and formats the request for you. It automatically generates a multipart/form-data body, the web standard for transferring attachments.&#x20;

To structure this transfer, the system creates its own unique separation identifier (called a boundary) allowing the destination server to clearly distinguish each sent file.

The generated request Header will look like this:&#x20;

```
Content-Type: multipart/form-data; boundary=fpzDzOf56Xecd3EcRuwZwVNnC8S5Ln0k
```

***

Attachments sent by users are accessible from the relevant conversation via a token-secured link.&#x20;

In the event of conversation purging, anonymization, or encryption, transmitted attachments are included: they will no longer be accessible according to the defined purging, anonymization, or encryption criteria.

## Example 5: Sending a single attachment

Sending an attachment to a web service assumes that an attachment has been uploaded by the user during the conversation.

If multiple attachments are uploaded during the same conversation, the attachment uploaded during the most recent interaction will be the one sent to the web service (this allows the user to change the attachment in case of a selection error from the chatbox).

The data of the attachment to be sent is accessible using the following three keys:

* `${DialogLastFileUploadedContent()}`
* `${DialogLastFileUploadedContentType()}`
* `${DialogLastFileUploadedName()}`

{% hint style="warning" %}
Before the **edge\_2025-12-09** version, the system used different variables.&#x20;

These variables are still functional but only retrieve the first file sent and are no longer updated. It is recommended to use the new function to handle multiple uploads.
{% endhint %}

The first keyword refers to the file content, the second to its type, and the third to its name.

In the "**Body**" area, these three keys can be used as part of JSON content; the value of `DialogLastFileUploadedContent` will be Base64 encoded.

<figure><img src="/files/YLsymPezZonYfT1IPR79" alt=""><figcaption></figcaption></figure>

In the "**Parameters**" area, only the `${DialogLastFileUploadedContent()}` key is required.&#x20;

When present, the corresponding file will be sent to the web service as multipart/form-data, along with its associated metadata (file name and content type).

<figure><img src="/files/AE0hLGRecxFvqgsCystl" alt=""><figcaption></figcaption></figure>

If the "**Body**" area is used to send a file to a web service, it does not make sense to also use the "**Parameters**" area for this purpose, and vice versa.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-en.dydu.ai/contents/web-services/configuration-examples-rest.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
