> For the complete documentation index, see [llms.txt](https://triway.gitbook.io/bi-direct/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://triway.gitbook.io/bi-direct/rest-to-soap.md).

# REST to SOAP

#### Bi-Direct endpoint for REST to SOAP: [https://tri-way.vercel.app/resttosoap](#bi-direct-endpoint-for-rest-to-soap-https-tri-way.vercel.app-resttosoap)

Just like a REST API call if you want to pass any data and the required data in the request body, you need to include a JSON object with the following keys:

* **Url**: The endpoint URL of the SOAP API you want to use
* **Method**: The HTTP method for the API call (POST, GET, PUT, DELETE, etc.)
* **Data** *(optional)*: The request body data for the POST or PUT request

### Example of a POST request

#### Normally this is how a soap request looks like

```
Host: www.dataaccess.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
```

```xml
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
      <ubiNum>1234</ubiNum>
    </NumberToWords>
  </soap12:Body>
</soap12:Envelope>
```

Output for the above-given soap request will look something like this

```xml
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <NumberToWordsResponse xmlns="http://www.dataaccess.com/webservicesserver/">
      <NumberToWordsResult>one thousand two hundred and thirty four</NumberToWordsResult>
    </NumberToWordsResponse>
  </soap12:Body>
</soap12:Envelope>
```

#### Example of a POST request made using Bi-Direct

#### Headers

{% code overflow="wrap" lineNumbers="true" %}

```javascript
headers: {
    'Content-Type': 'application/json'
  }
```

{% endcode %}

#### Request Body (POST request)

{% hint style="info" %}

#### Note

The input data for the SOAP request is specified in the `"Data"` property. The `"NumberToWords"` property specifies the name of the SOAP operation, and the `ubiNum` property specifies the input parameter. The `"#"` property specifies the value of the input parameter, which is `unsignedLong`. The `"@"` the property specifies the namespace declaration for the `NumberToWords` element.
{% endhint %}

{% code lineNumbers="true" %}

```json
{
  "Url": "https://www.dataaccess.com//webservicesserver/NumberConversion.wso?op=NumberToWords",
  "Method": "POST",
  "Data": {
    "NumberToWords": {
      "@": {
        "xmlns": "http://www.dataaccess.com/webservicesserver/"
      },
      "ubiNum": {
        "#": "1234"
      }
    }
  }
}
```

{% endcode %}

<details>

<summary>Generated output for the given POST request</summary>

```json
{
  "soap:Envelope": {
    "$": {
      "xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/"
    },
    "soap:Body": [
      {
        "m:NumberToWordsResponse": [
          {
            "$": {
              "xmlns:m": "http://www.dataaccess.com/webservicesserver/"
            },
            "m:NumberToWordsResult": [
              "one thousand two hundred and thirty four "
            ]
          }
        ]
      }
    ]
  }
}
```

</details>

<details>

<summary>Javascript code (Axios)</summary>

{% code lineNumbers="true" %}

```javascript
let headersList = {
  "Content-Type": "application/json"
 }
 
 let bodyContent = JSON.stringify({
  "Url": "https://www.dataaccess.com//webservicesserver/NumberConversion.wso?op=NumberToWords",
  "Method": "POST",
  "Data": {
    "NumberToWords": {
      "@": {
        "xmlns": "http://www.dataaccess.com/webservicesserver/"
      },
      "ubiNum": {
        "#": "1234"
      }
    }
  }
});

async function makeRequest() { 
 let response = await fetch("https://tri-way.vercel.app/resttosoap", { 
   method: "POST",
   body: bodyContent,
   headers: headersList
 });
 
 let data = await response.text();
console.log(data);
}
 
makeRequest()
```

{% endcode %}

</details>
