# Setting up a Prima Solutions connection

## Introduction

Typically, connectors are defined with endpoints which determine exactly what data is being requested (pull customer records, post product details, etc.). However, the Prima Solutions connector works in a different way, with two generic endpoints:

* comwsomhandler
* wsomhandler

The actual data required for a request must be passed into the Prima Solutions connection shape, as part of your process flow. You do this via a [manual payload](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/manual-payload-shape) shape.

{% hint style="info" %}
Whatever is defined for the manual payload is passed into the body of the subsequent Prima Solutions connection request.
{% endhint %}

Finally - once a successful connection is made - the response must be converted from XML to JSON, ready for onward processing.

With this in mind, a process flow that needs to pull data from Prima Solutions will usually require three shapes in the following sequence:

1. **Manual payload** shape, which includes the required [request data](#request-data) in an XML string
2. **Connection** shape, configured with a Prima Solutions endpoint&#x20;
3. **Script** shape, configured with an [XML to JSON conversion script](#converting-response-xml-to-json)&#x20;

For example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FYGfpO3i25I4UkJBB8UGO%2Fprima%20solutions%201.png?alt=media&#x26;token=18afb18c-14d6-4181-ad46-3f2a7ea2afaa" alt=""><figcaption></figcaption></figure>

## Request data

Request data to be passed into a Prima Solutions connection shape must be based on the *Prima Web Services XML Schema Definition*. Some examples are shown below.&#x20;

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FfUVdhc1UgMWObOesLjkS%2Ficon%20eye.png?alt=media&#x26;token=c8b6d3a9-b5a9-4cb0-8aeb-00bd39c00b60" alt="" data-size="line"> Example: NewOrder</summary>

The example below shows a `NewOrder` request (XML string):

{% code title="With HTML entities" overflow="wrap" lineNumbers="true" %}

```xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<Request RequestType="NewOrder">
  <Data Customer="&quot;&quot;" CustDef="&quot;&quot;" VatInclusive="&quot;&quot;" TPGUID="&quot;&quot;" CustomerRef="&quot;&quot;" CustomerForename="&quot;&quot;" CustomerSurname="&quot;&quot;" CustomerPhone="&quot;&quot;" CustomerEmail="&quot;&quot;" AddrLine1="&quot;&quot;" AddrLine2="&quot;&quot;" AddrLine3="&quot;&quot;" AddrLine4="&quot;&quot;" AddrLine5="&quot;&quot;" AddrLine6="&quot;&quot;" Country="&quot;&quot;" PostCode="&quot;&quot;">
    <OrderInvoiceData InvoiceTitle="&quot;&quot;" InvoiceForename="&quot;&quot;" InvoiceSurname="&quot;&quot;" InvoicePhone="&quot;&quot;" InvoiceEmail="&quot;&quot;" InvoiceAddrLine1="&quot;&quot;" InvoiceAddrLine2="&quot;&quot;" InvoiceAddrLine3="&quot;&quot;" InvoiceAddrLine4="&quot;&quot;" InvoiceAddrLine5="&quot;&quot;" InvoiceAddrLine6="&quot;&quot;" InvoiceCountry="&quot;&quot;" InvoicePostCode="&quot;&quot;"/>
    <OrderHeaderData Currency="&quot;&quot;" OrderEmail="&quot;&quot;" OrderStatus="&quot;&quot;" OrderCategory="&quot;&quot;" OrderDate="&quot;&quot;" SendToApproval="&quot;&quot;" SourceMedia="&quot;&quot;" Carrier="&quot;&quot;" CarrServ="&quot;&quot;"/>
    <OrderChargeData Charge="&quot;&quot;" ChargeValue="&quot;&quot;"/>
    <OrderPaymentData TranAmount="&quot;&quot;" PayMethod="&quot;&quot;" SubPayMethod="&quot;&quot;" PayAuthRef="&quot;&quot;" AuthRef="&quot;&quot;" AuthDate="&quot;&quot;" AuthTime="&quot;&quot;"/>
    <OrderLineData Product="&quot;&quot;" Quantity="&quot;&quot;" Price="&quot;&quot;" MtrxCode1="&quot;&quot;" MtrxCode2="&quot;&quot;"/>
  </Data>
</Request>
```

{% endcode %}

{% code title="Without HTML entities" overflow="wrap" lineNumbers="true" %}

```html
<?xml version="1.0" encoding="ISO-8859-1"?>
<Request RequestType="NewOrder">
  <Data Customer="" CustDef="" VatInclusive="" TPGUID="" CustomerRef="" CustomerForename="" CustomerSurname="" CustomerPhone="" CustomerEmail="" AddrLine1="" AddrLine2="" AddrLine3="" AddrLine4="" AddrLine5="" AddrLine6="" Country="" PostCode="">
    <OrderInvoiceData InvoiceTitle="" InvoiceForename="" InvoiceSurname="" InvoicePhone="" InvoiceEmail="" InvoiceAddrLine1="" InvoiceAddrLine2="" InvoiceAddrLine3="" InvoiceAddrLine4="" InvoiceAddrLine5="" InvoiceAddrLine6="" InvoiceCountry="" InvoicePostCode=""/>
    <OrderHeaderData Currency="" OrderEmail="" OrderStatus="" OrderCategory="" OrderDate="" SendToApproval="" SourceMedia="" Carrier="" CarrServ=""/>
    <OrderChargeData Charge="" ChargeValue=""/>
    <OrderPaymentData TranAmount="" PayMethod="" SubPayMethod="" PayAuthRef="" AuthRef="" AuthDate="" AuthTime=""/>
    <OrderLineData Product="" Quantity="" Price="" MtrxCode1="" MtrxCode2=""/>
  </Data>
</Request>
```

{% endcode %}

</details>

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FfUVdhc1UgMWObOesLjkS%2Ficon%20eye.png?alt=media&#x26;token=c8b6d3a9-b5a9-4cb0-8aeb-00bd39c00b60" alt="" data-size="line"> Example: ProductAvailableToSell</summary>

The example below shows a `ProductAvailableToSell` request (XML string):

{% code title="With HTML entities" overflow="wrap" lineNumbers="true" %}

```xml
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
   &lt;Request RequestType=&quot;ProductAvailableToSell&quot;&gt;
   &lt;Data ProductFrom=&quot;&quot; ProductTo=&quot;&quot; WareHouse=&quot;&quot; IncludeDisallowed=&quot;&quot; IncludeProhibited=&quot;&quot;/&gt;
   &lt;/Request&gt;
```

{% endcode %}

{% code title="Without HTML entities" overflow="wrap" lineNumbers="true" %}

```html
<?xml version="1.0" encoding="ISO-8859-1"?>
<Request RequestType="ProductAvailableToSell">
   <Data ProductFrom="" ProductTo="" WareHouse="" IncludeDisallowed="" IncludeProhibited=""/>
</Request>

```

{% endcode %}

The response would be in the form below:

{% code title="With HTML entities" overflow="wrap" lineNumbers="true" %}

```xml
<?xml version="1.0" encoding="ISO-8859-1" ?> <Result Company="1" RequestStatus="OK" RequestType="ProductAvailableToSell"><Data><sku AvailableDate="" AvailableQuantity="0" FTSQty="0" MtrxCode1="" MtrxCode2="" MtrxCode3="" MtrxCode4="" Product="1000"/><sku AvailableDate="" AvailableQuantity="0" FTSQty="0" MtrxCode1="" MtrxCode2="" MtrxCode3="" MtrxCode4="" Product="1001"/></Data></Result>
```

{% endcode %}

Notice that the response is returned as an XML string. For onward processing you must [convert this to a JSON payload, using a custom script](#converting-response-xml-to-json).

</details>

## Converting response XML to JSON

Before the response from a Prima Solutions request can be be processed, it must be converted to a JSON payload. To do this, you should create an XML to JSON conversion script and add this to a [script shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/script-shape) in your process flow.
