You'll now send order status information back to ERP to complete the bi-directional flow.

ERP has provided an endpoint called `sendOrderInfo` and requested that the payload is structured as:

```json
{
    "order": {
        "workOrderName": "260526-001",
        "itemName": "SC-2024",
        "reqdQty": 30000,
        "actualQty": 28500
    }
}
```

In a real project, the ERP team gives you the URL of this endpoint on their system. For this training, the ERP simulator you installed in [Get Orders from ERP](./2-scheduling-orders-from-erp.md) provides it at `http://localhost:8088/system/webdev/kanoaERPSim/api/sendOrderInfo`. You call it from MES with Ignition's `system.net.httpPost()` function.

::::action[Send order status to the ERP simulator]

1. Open the ERP simulator in a browser so you can see what it receives.
2. Copy the following code block into the Script Console in the Ignition Designer. It doesn't matter from which project.
3. Set `GATEWAY` to the address you open the gateway with in your browser, then run it.

:::info[Which gateway address?]
The Script Console runs on your computer, not on the gateway, so it needs the address your computer uses to reach the gateway: the one in your browser's address bar, such as `http://localhost:8088` or `https://kanoa-dev.localtest.me`. If your gateway runs in Docker or on another machine, `localhost:8088` fails with `Connection refused`.

Scripts that run on the gateway itself, like the simulator calling `sendMO` or a gateway event script calling ERP, use `http://localhost:8088`.
:::

<details>
<summary>Script Console code</summary>

```python
# The address you open the gateway with in your browser, e.g. 'http://localhost:8088'
GATEWAY = 'http://localhost:8088'

def sendOrderUpdateToERP(orderInfo):

	url = GATEWAY + "/system/webdev/kanoaERPSim/api/sendOrderInfo"
	payload = {'order': orderInfo}
	try:
		resp = system.net.httpPost(url, postData=system.util.jsonEncode(payload), contentType="application/json")
	except:
		# Turn the common failures into something you can act on.
		import sys
		error = str(sys.exc_info()[1])
		if 'Connection refused' in error:
			return 'Could not connect to %s. Set GATEWAY to the address you open the gateway with in your browser.' % GATEWAY
		if 'code: 402' in error:
			return 'The WebDev trial has expired. On the Gateway web page, click Reset Trial, then run this again.'
		if 'code: 404' in error:
			return 'Nothing at %s. Check that the ERP simulator project is installed and named kanoaERPSim.' % url
		return 'Request failed: %s' % error

	return system.util.jsonDecode(resp)

# Send only the fields ERP asked for, not the whole Kanoa production order.
orderInfo = {
	"workOrderName": "260526-001",
	"itemName": "SC-2024",
	"reqdQty": 30000,
	"actualQty": 28500
}

print sendOrderUpdateToERP(orderInfo)
```
</details>

The Script Console prints the simulator's reply, `{"ok": true, ...}`, and the ERP simulator opens a popup showing the order it received. If the call fails, it prints what went wrong instead, such as an expired WebDev trial (HTTP 402) or a gateway address it can't reach.
::::
