Contact Us 1-800-596-4880

NetSuite OpenAir 2.0 Examples - Mule 4

This example shows how to add, modify, read, and delete two customers from the NetSuite OpenAir instance by using the same request. This example contains five flows:

  1. The first flow configures a template for the input.

  2. The second flow adds two customers from the input.

  3. The third flow modifies the customer information of the two customers.

  4. The fourth flow retrieves the modified customer information of the two customers.

  5. The fifth flow deletes the two customers.

The following screenshot shows the flows in Anypoint Studio:

The five flows in Anypoint Studio

Create the First Flow

The first flow configures an HTML template for the input to later use when adding, modifying, reading, and deleting the two customers. Configuring this flow involves creating a new Mule project, configuring the HTTP Listener source, and adding the Parse Template component.

Configure the HTTP Listener Source

Configure the HTTP Listener source to initiate a Mule flow when a call is made to the default path (/):

  1. Create a new Mule project in Studio.

  2. From the Mule Palette view, select HTTP and drag the Listener source to the canvas.

  3. In the properties window, click + next to the Connector configuration field to add a global element.

  4. In the Display Name field, enter Listener and accept the default values.

Add the Parse Template Component

Add the Parse Template component to create a template for an HTML form (form.html), which is located in the main resources folder. The example uses this form to later add, modify, read, and delete the two customers:

  1. From the Mule Palette view, select Core and drag the Parse Template component next to the Listener source.

  2. In the Location field, enter form.html.

Create the Second Flow

The second flow adds the two customers from the customer name and company input values. Configuring this flow involves configuring the HTTP Listener source, adding the Logger component, adding the Transform Message component, adding the Add operation, adding another Transform Message component, and adding another Logger component.

Configure the HTTP Listener Source

Configure the HTTP Listener source to initiate a Mule flow when a call is made to the /add path:

  1. From the Mule Palette view, select HTTP and drag the Listener source to the canvas.

  2. In the properties window, click + next to the Connector configuration field to add a global element.

  3. In the Display Name field, enter Listener.

  4. In the Path field, enter /add.

Add the Logger Component

Add the Logger component to log the payload:

  1. From the Mule Palette view, select Core and drag the Logger component next to the Listener source.

  2. In the Message field, enter payload.

Add the Transform Message Component

Add the Transform Message component to transform the customer name and company input values of the two customers to XML to add them later:

  1. From the Mule Palette view, select Core and drag the Transform Message component next to the Logger component.

  2. In the properties window, overlay the brackets in the Output section with this DataWeave code:

    %dw 2.0
    output application/xml
    ns ns0 http://namespaces.soaplite.com/perl
    ---
    {
    	ArrayOfoaBase: {
    		oaBase: {
    			ns0#oaCustomer: {
    				name: payload.customerName_1,
             		company: payload.customerCompany_1
    			},
    			ns0#oaCustomer: {
    				name: payload.customerName_2,
    				company: payload.customerCompany_2
    			}
    		}
    	}
    }

Add the Add Operation

Add the Add operation to add the two customers:

  1. From the Mule Palette view, select NetSuite OpenAir and drag the Add operation next to the Transform Message component.

  2. In the properties window, complete the following fields:

    Field Value

    oaObject

    oaCustomer

    Request

    payload

Add Another Transform Message Component

Add another Transform Message component to transform the customer name and company input values of the two customers to JSON:

  1. From the Mule Palette view, select Core and drag the Transform Message component next to the Add operation.

  2. In the properties window, overlay the brackets in the Output section with this DataWeave code:

    %dw 2.0
    output application/json
    ns ns0 http://namespaces.soaplite.com/perl
    ---
    {
    	customerID_1: payload.ns0#ArrayOfUpdateResult.*updateResult[0].id,
    	customerID_2: payload.ns0#ArrayOfUpdateResult.*updateResult[1].id
    }

Add Another Logger Component

Add another Logger component to log the payload:

  1. From the Mule Palette view, select Core and drag the Logger component next to the Transform Message component.

  2. In the Message field, enter payload.

Create the Third Flow

The third flow modifies the customer information of the two customers. Configuring this flow involves configuring the HTTP Listener source, adding the Logger component, adding the Transform Message component, adding the Modify operation, adding another Transform Message component, and adding another Logger component.

Configure the HTTP Listener Source

Configure the HTTP Listener source to initiate a Mule flow when a call is made to the /modify path:

  1. From the Mule Palette view, select HTTP and drag the Listener source to the canvas.

  2. In the properties window, click + next to the Connector configuration field to add a global element.

  3. In the Display Name field, enter Listener.

  4. In the Path field, enter /modify.

Add the Logger Component

Add the Logger component to log the payload:

  1. From the Mule Palette view, select Core and drag the Logger component next to the Listener source.

  2. In the Message field, enter payload.

Add the Transform Message Component

Add the Transform Message component to transform the customer name and company input values of the two customers to XML to modify them later:

  1. From the Mule Palette view, select Core and drag the Transform Message component next to the Logger component.

  2. In the properties window, overlay the brackets in the Output section with this DataWeave code:

    %dw 2.0
    output application/xml
    ns ns0 http://namespaces.soaplite.com/perl
    ---
    //Some output fields where skipped as the structure is too deep (more than 2 levels).
    //To add missing fields click on the scaffold icon (second on the toolbar).
    {
    	modifyRequest: {
    		ArrayOfoaBase: {
    			oaBase : {
    				ns0#oaCustomer: {
    					id: payload.modifyCustomerID_1,
    					name: payload.modifyCustomerName_1,
    					company: payload.modifyCustomerCompany_1
    				},
    				ns0#oaCustomer: {
    					id: payload.modifyCustomerID_2,
    					name: payload.modifyCustomerName_2,
    					company: payload.modifyCustomerCompany_2
    				}
    			}
    		}
    
    	}
    }

Add the Modify Operation

Add the Modify operation to modify the customer information of the two customers:

  1. From the Mule Palette view, select NetSuite OpenAir and drag the Modify operation next to the Transform Message component.

  2. In the properties window, complete the following fields:

    Field Value

    oaObject

    oaCustomer

    Request

    payload

Add Another Transform Message Component

Add another Transform Message component to transform the modified customer name and company values of the two customers to JSON:

  1. From the Mule Palette view, select Core and drag the Transform Message component next to the Modify operation.

  2. In the properties window, overlay the brackets in the Output section with this DataWeave code:

    %dw 2.0
    output application/json
    ns ns0 http://namespaces.soaplite.com/perl
    ---
    {
    	customerID_1: payload.ns0#ArrayOfUpdateResult.*updateResult[0].id,
    	customerStatus_1: payload.ns0#ArrayOfUpdateResult.*updateResult[0].status,
    	customerID_2: payload.ns0#ArrayOfUpdateResult.*updateResult[1].id,
    	customerStatus_2: payload.ns0#ArrayOfUpdateResult.*updateResult[1].status
    }

Add Another Logger Component

Add another Logger component to log the payload:

  1. From the Mule Palette view, select Core and drag the Logger component next to the Transform Message component.

  2. In the Message field, enter payload.

Create the Fourth Flow

The fourth flow retrieves the modified customer information of the two customers. Configuring this flow involves configuring the HTTP Listener source, adding the Logger component, adding the Transform Message component, adding the Read operation, adding another Transform Message component, and adding another Logger component.

Configure the HTTP Listener Source

Configure the HTTP Listener source to initiate a Mule flow when a call is made to the /read path:

  1. From the Mule Palette view, select HTTP and drag the Listener source to the canvas.

  2. In the properties window, click + next to the Connector configuration field to add a global element.

  3. In the Display Name field, enter Listener.

  4. In the Path field, enter /read.

Add the Logger Component

Add the Logger component to log the payload:

  1. From the Mule Palette view, select Core and drag the Logger component next to the Listener source.

  2. In the Message field, enter payload.

Add the Transform Message Component

Add the Transform Message component to transform the customer name and company input values of the two customers to XML to read them later:

  1. From the Mule Palette view, select Core and drag the Transform Message component next to the Logger component.

  2. In the properties window, overlay the brackets in the Output section with this DataWeave code:

    %dw 2.0
    output application/xml
    ns ns0 http://namespaces.soaplite.com/perl
    ---
    {
    	ns0#ArrayOfReadRequest: {
    		readRequest: {
    			method: "equal to",
    			fields: "id,name,company",
    			"type": "Customer",
    			objects :{
    				oaBase: {
    					oaCustomer: {
    						id: payload.readCustomerID_1
    					}
    				}
    			}
    		},
    
    		readRequest: {
    			method: "equal to",
    			fields: "id,name,company",
    			"type": "Customer",
    			objects :{
    				oaBase: {
    					oaCustomer: {
    						id: payload.readCustomerID_2
    					}
    				}
    			}
    		}
    
    	}
    }

Add the Read Operation

Add the Read operation to retrieve the modified customer information of the two customers:

  1. From the Mule Palette view, select NetSuite OpenAir and drag the Read operation next to the Transform Message component.

  2. In the properties window, complete the following fields:

    Field Value

    oaObject

    oaCustomer

    Request

    payload

Add Another Transform Message Component

Add another Transform Message component to transform the modified customer name and company values of the two customers to JSON:

  1. From the Mule Palette view, select Core and drag the Transform Message component next to the Read operation.

  2. In the properties window, overlay the brackets in the Output section with this DataWeave code:

    %dw 2.0
    output application/json
    ns ns0 http://namespaces.soaplite.com/perl
    ---
    {
    	customerID_1: payload.ns0#ArrayOfReadResult.*readResult[0].objects.oaBase.oaCustomer.id,
    	customerName_1: payload.ns0#ArrayOfReadResult.*readResult[0].objects.oaBase.oaCustomer.name,
    	customerCompany_1: payload.ns0#ArrayOfReadResult.*readResult[0].objects.oaBase.oaCustomer.company,
    
    	customerID_2: payload.ns0#ArrayOfReadResult.*readResult[1].objects.oaBase.oaCustomer.id,
    	customerName_2: payload.ns0#ArrayOfReadResult.*readResult[1].objects.oaBase.oaCustomer.name,
    	customerCompany_2: payload.ns0#ArrayOfReadResult.*readResult[1].objects.oaBase.oaCustomer.company
    }

Add Another Logger Component

Add another Logger component to log the payload:

  1. From the Mule Palette view, select Core and drag the Logger component next to the Transform Message component.

  2. In the Message field, enter payload.

Create the Fifth Flow

The fifth flow deletes the customer information of the two customers. Configuring this flow involves configuring the HTTP Listener source, adding the Logger component, adding the Transform Message component, adding the Delete operation, adding another Transform Message component, and adding another Logger component.

Configure the HTTP Listener Source

Configure the HTTP Listener source to initiate a Mule flow when a call is made to the /delete path:

  1. From the Mule Palette view, select HTTP and drag the Listener source to the canvas.

  2. In the properties window, click + next to the Connector configuration field to add a global element.

  3. In the Display Name field, enter Listener.

  4. In the Path field, enter /delete.

Add the Logger Component

Add the Logger component to log the payload:

  1. From the Mule Palette view, select Core and drag the Logger component next to the Listener source.

  2. In the Message field, enter payload.

Add the Transform Message Component

Add the Transform Message component to transform the customer name and company input values of the two customers to XML to delete them later:

  1. From the Mule Palette view, select Core and drag the Transform Message component next to the Logger component.

  2. In the properties window, overlay the brackets in the Output section with this DataWeave code:

    %dw 2.0
    output application/xml
    ns ns0 http://namespaces.soaplite.com/perl
    ---
    {
    	ArrayOfoaBase: {
    		oaBase: {
    			ns0#oaCustomer: {
    				id: payload.deleteCustomerID_1
    			},
    			ns0#oaCustomer: {
    				id: payload.deleteCustomerID_2
    			}
    		}
    	}
    }

Add the Delete Operation

Add the Delete operation to delete the customer information of the two customers:

  1. From the Mule Palette view, select NetSuite OpenAir and drag the Delete operation next to the Transform Message component.

  2. In the properties window, complete the following fields:

    Field Value

    oaObject

    oaCustomer

    Request

    payload

Add Another Transform Message Component

Add another Transform Message component to transform the customer name and company values of the two customers to JSON:

  1. From the Mule Palette view, select Core and drag the Transform Message component next to the Delete operation.

  2. In the properties window, overlay the brackets in the Output section with this DataWeave code:

    %dw 2.0
    output application/json
    ns ns0 http://namespaces.soaplite.com/perl
    ---
    {
    	Status1: payload.ns0#ArrayOfUpdateResult.*updateResult[0].status,
    	Status2: payload.ns0#ArrayOfUpdateResult.*updateResult[1].status
    }

Add Another Logger Component

Add another Logger component to log the payload:

  1. From the Mule Palette view, select Core and drag the Logger component next to the Transform Message component.

  2. In the Message field, enter payload.

XML for the Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule app:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:openair="http://www.mulesoft.org/schema/mule/openair"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/openair http://www.mulesoft.org/schema/mule/openair/current/mule-openair.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
	<configuration-properties file="mule-app.properties"/>
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="73024093-eb8a-4f84-ad72-64fef89717c7" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<openair:config name="Open_Air_Config" doc:name="Open Air Config" doc:id="25f013ac-3701-466f-8481-ac050e080cb2" >
		<openair:login-authentication-connection company="${config.company}" username="${config.username}" password="${config.password}" apiNamespace="${config.apiNamespace}" apiKey="${config.apiKey}" />
	</openair:config>
	<flow name="openair-connector-add-modify-read-deleteFlow" doc:id="6323ab9b-99e7-4e25-bc1d-e1153f158299" >
		<http:listener doc:name="Listener" doc:id="02cc2682-4ee7-4aa1-94f3-592d4360f807" config-ref="HTTP_Listener_config" path="/"/>
		<parse-template doc:name="Parse Template" doc:id="608f90f9-ae3f-483f-ad59-d7036cb2b5ed" location="form.html"/>
	</flow>
	<flow name="openair-connector-add-modify-read-deleteFlow-Add" doc:id="1b5f6a8d-01a0-438a-9849-613c0f33fbda" >
		<http:listener doc:name="Listener" doc:id="ea825843-a617-435e-86de-15c757765b76" config-ref="HTTP_Listener_config" path="/add"/>
		<logger level="INFO" doc:name="Logger" doc:id="49efe1ad-9c8f-460f-9a34-a25aaa15c286" message="#[payload]"/>
		<ee:transform doc:name="Transform Message" doc:id="00bfea96-207d-45af-b1b9-b455f048471b" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
ns ns0 http://namespaces.soaplite.com/perl
---
{
	ArrayOfoaBase: {
		oaBase: {
			ns0#oaCustomer: {
				name: payload.customerName_1,
         		company: payload.customerCompany_1
			},
			ns0#oaCustomer: {
				name: payload.customerName_2,
				company: payload.customerCompany_2
			}
		}
	}
}]]></ee:set-payload>
			</ee:message>
			<ee:variables >
			</ee:variables>
		</ee:transform>
		<openair:add doc:name="Add" doc:id="177d9d3f-d82a-4411-b34a-a810345dbf25" config-ref="Open_Air_Config" oaObject="oaCustomer">
		</openair:add>
		<ee:transform doc:name="Transform Message" doc:id="80578431-28e8-41cf-ac92-caf611aba0db" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
ns ns0 http://namespaces.soaplite.com/perl
---
{
	customerID_1: payload.ns0#ArrayOfUpdateResult.*updateResult[0].id,
	customerID_2: payload.ns0#ArrayOfUpdateResult.*updateResult[1].id
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" doc:id="b2e56a60-e751-416b-8d12-c84fe02101e1" message="#[payload]"/>
	</flow>
	<flow name="openair-connector-add-modify-read-deleteFlow-modify" doc:id="cdfcc099-8807-40eb-ba65-3ec654636351" >
		<http:listener doc:name="Listener" doc:id="bcffd8e9-6b12-4aec-8eb5-95e21f41c9ab" config-ref="HTTP_Listener_config" path="/modify"/>
		<logger level="INFO" doc:name="Logger" doc:id="be280d6d-dc66-44c4-9e7c-b74bc14da16e" message="#[payload]"/>
		<ee:transform doc:name="Transform Message" doc:id="08721573-0739-42cd-b635-f0de1f6831de" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
ns ns0 http://namespaces.soaplite.com/perl
---
//Some output fields where skipped as the structure is too deep (more than 2 levels).
//To add missing fields click on the scaffold icon (second on the toolbar).
{
	modifyRequest: {
		ArrayOfoaBase: {
			oaBase : {
				ns0#oaCustomer: {
					id: payload.modifyCustomerID_1,
					name: payload.modifyCustomerName_1,
					company: payload.modifyCustomerCompany_1
				},
				ns0#oaCustomer: {
					id: payload.modifyCustomerID_2,
					name: payload.modifyCustomerName_2,
					company: payload.modifyCustomerCompany_2
				}
			}
		}

	}
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<openair:modify doc:name="Modify" doc:id="6ad0f4b2-f1bd-4475-a600-207258145461" config-ref="Open_Air_Config" oaObject="oaCustomer"/>
		<ee:transform doc:name="Transform Message" doc:id="eeec400a-41ec-43e4-949b-ac9b1ae3fb5f" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
ns ns0 http://namespaces.soaplite.com/perl
---
{
	customerID_1: payload.ns0#ArrayOfUpdateResult.*updateResult[0].id,
	customerStatus_1: payload.ns0#ArrayOfUpdateResult.*updateResult[0].status,
	customerID_2: payload.ns0#ArrayOfUpdateResult.*updateResult[1].id,
	customerStatus_2: payload.ns0#ArrayOfUpdateResult.*updateResult[1].status
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" doc:id="5dbcdc8d-ab38-4841-ad4a-0b6288891310" message="#[payload]"/>
	</flow>
	<flow name="openair-connector-add-modify-read-deleteFlow-read" doc:id="bfe3c8ab-f9de-4d85-8e0f-6414b09aafd7" >
		<http:listener doc:name="Listener" doc:id="2bf6d5ba-447d-49cf-bc9c-ea903dca07ea" config-ref="HTTP_Listener_config" path="/read" />
		<logger level="INFO" doc:name="Logger" doc:id="8a62904a-4d56-4924-a6c4-ec0a93d10377" message="#[payload]" />
		<ee:transform doc:name="Transform Message" doc:id="2f2377c3-d284-46a4-aaf4-7271e968c6bb" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
ns ns0 http://namespaces.soaplite.com/perl
---
{
	ns0#ArrayOfReadRequest: {
		readRequest: {
			method: "equal to",
			fields: "id,name,company",
			"type": "Customer",
			objects :{
				oaBase: {
					oaCustomer: {
						id: payload.readCustomerID_1
					}
				}
			}
		},

		readRequest: {
			method: "equal to",
			fields: "id,name,company",
			"type": "Customer",
			objects :{
				oaBase: {
					oaCustomer: {
						id: payload.readCustomerID_2
					}
				}
			}
		}

	}
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<openair:read doc:name="Read" doc:id="4f262aba-ad1a-4f14-9c07-55b46b5c52d9" config-ref="Open_Air_Config" oaObject="oaCustomer"/>
		<ee:transform doc:name="Transform Message" doc:id="1cd3247b-a63a-431b-938c-e882d943dd81" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
ns ns0 http://namespaces.soaplite.com/perl
---
{
	customerID_1: payload.ns0#ArrayOfReadResult.*readResult[0].objects.oaBase.oaCustomer.id,
	customerName_1: payload.ns0#ArrayOfReadResult.*readResult[0].objects.oaBase.oaCustomer.name,
	customerCompany_1: payload.ns0#ArrayOfReadResult.*readResult[0].objects.oaBase.oaCustomer.company,

	customerID_2: payload.ns0#ArrayOfReadResult.*readResult[1].objects.oaBase.oaCustomer.id,
	customerName_2: payload.ns0#ArrayOfReadResult.*readResult[1].objects.oaBase.oaCustomer.name,
	customerCompany_2: payload.ns0#ArrayOfReadResult.*readResult[1].objects.oaBase.oaCustomer.company
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" doc:id="21d10cfa-9071-4dad-a5a3-d3c85dca261d" message="#[payload]" />
	</flow>
	<flow name="openair-connector-add-modify-read-deleteFlow-delete" doc:id="43c7995b-27fd-4062-a393-df7afdd90905" >
		<http:listener doc:name="Listener" doc:id="af239902-3b8a-40b1-8edf-3756a5857e55" config-ref="HTTP_Listener_config" path="/delete"/>
		<logger level="INFO" doc:name="Logger" doc:id="fb07ebc0-10db-4ac8-8803-fdcfc6cf1913" message="#[payload]"/>
		<ee:transform doc:name="Transform Message" doc:id="743eddce-966c-4fad-b5ec-b753aa5894e9" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
ns ns0 http://namespaces.soaplite.com/perl
---
{
	ArrayOfoaBase: {
		oaBase: {
			ns0#oaCustomer: {
				id: payload.deleteCustomerID_1
			},
			ns0#oaCustomer: {
				id: payload.deleteCustomerID_2
			}
		}
	}
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<openair:delete doc:name="Delete" doc:id="1621fcd1-536e-4be7-b8d1-452cd35a2749" config-ref="Open_Air_Config" oaObject="oaCustomer"/>
		<ee:transform doc:name="Transform Message" doc:id="432b8eeb-18f3-4c9d-9be0-ae0fede825e5" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
ns ns0 http://namespaces.soaplite.com/perl
---
{
	Status1: payload.ns0#ArrayOfUpdateResult.*updateResult[0].status,
	Status2: payload.ns0#ArrayOfUpdateResult.*updateResult[1].status
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" doc:id="edc70093-c05e-4c8c-ad92-0de46f990d06" message="#[payload]"/>
	</flow>
</mule>
View on GitHub