> For the complete documentation index, see [llms.txt](https://docs.chatlayer.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chatlayer.ai/integrateandcode/code-action/making-soap-requests.md).

# \[Example] Making SOAP requests

You can use the [API Action](/integrateandcode/custom-back-end-integrations.md#api-plugin) to make REST-based API calls. If the API you're integrating with is SOAP-based, the[ Code Editor](/integrateandcode/code-action.md) is the tool for you.

### Example

The following is an example of how you can leverage the [fetch ](/integrateandcode/code-action.md#fetch)library embedded in the Code Editor runtime to perform SOAP requests.

The `input` variable should contain any stringified number, like "500". We build the XML body through a [template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals?retiredLocale=nl) and substitute the input value. We then extract the response value through Regex. The output message in the chat will then contain the number as words, "five hundred" in the case of our example.

```javascript
// We make use of the following public API
// https://documenter.getpostman.com/view/8854915/Szf26WHn

const { input } = args;

const url = "https://www.dataaccess.com/webservicesserver/NumberConversion.wso";

// The request body
const body = `<?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
      <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
        <ubiNum>${input}</ubiNum>
      </NumberToWords>
    </soap:Body>
  </soap:Envelope>
`;

const headers = {
  // Additional headers may be required
  // dpending on your server implementation
  "Content-Type": "text/xml; charset=utf-8",
};

const options = { method: "POST", headers, body };

const chatlayer = ChatlayerResponseBuilder();

try {
  // Perform the request to the SOAP api
  const response = await fetch(url, options);
  
  // Extract the text value from the response
  const xmlResponse = await response.text();
  
  // Build and match the RegExp to extract data from the response
  const regExp = new RegExp(
    "<m:NumberToWordsResult>(.*?)</m:NumberToWordsResult>"
  );
  const match = xmlResponse.match(regExp);
  if (!match) {
    throw new Error("Could not find the given number");
  }
  const result = match[1];
  chatlayer.addMessage(result);
} catch (ex) {
  chatlayer.addMessage(ex.toString());
} finally {
  chatlayer.send();
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.chatlayer.ai/integrateandcode/code-action/making-soap-requests.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
