> 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/chatlayer-documentation-pt-br/integrateandcode/code-action/making-soap-requests.md).

# \[Exemplo] Fazendo solicitações SOAP

Você pode usar o [Ação de API](/chatlayer-documentation-pt-br/integrateandcode/custom-back-end-integrations.md#api-plugin) para fazer chamadas de API baseadas em REST. Se a API com a qual você está integrando for baseada em SOAP, o[ Editor de Código](/chatlayer-documentation-pt-br/integrateandcode/code-action.md) é a ferramenta certa para você.

### Exemplo

A seguir está um exemplo de como você pode aproveitar a [fetch ](/chatlayer-documentation-pt-br/integrateandcode/code-action.md#fetch)biblioteca incorporada ao runtime do Editor de Código para realizar solicitações SOAP.

A `input` variável deve conter qualquer número em formato de string, como "500". Construímos o corpo XML por meio de um [literal de template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals?retiredLocale=nl) e substituímos o valor de entrada. Em seguida, extraímos o valor da resposta por meio de Regex. A mensagem de saída no chat conterá então o número por extenso, "quinhentos", no caso do nosso exemplo.

```javascript
// Fazemos uso da seguinte API pública
// https://documenter.getpostman.com/view/8854915/Szf26WHn

const { input } = args;

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

// O corpo da requisição
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 = {
  // Cabeçalhos adicionais podem ser necessários
  // dependendo da implementação do seu servidor
  "Content-Type": "text/xml; charset=utf-8",
};

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

const chatlayer = ChatlayerResponseBuilder();

try {
  // Faz a requisição para a API SOAP
  const response = await fetch(url, options);
  
  // Extrai o valor de texto da resposta
  const xmlResponse = await response.text();
  
  // Monta e faz a correspondência da RegExp para extrair dados da resposta
  const regExp = new RegExp(
    "<m:NumberToWordsResult>(.*?)</m:NumberToWordsResult>"
  );
  const match = xmlResponse.match(regExp);
  if (!match) {
    throw new Error("Não foi possível encontrar o número fornecido");
  }
  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/chatlayer-documentation-pt-br/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.
