# WebRequest in MetaTrader - How Trade Sync Works

> WebRequest is the MetaTrader function that enables EA-to-server communication. Here is how it works and why it needs to be configured for journal sync.

**Tags:** webrequest, mt4, mt5, technical, ea-sync
**URL:** https://traderjournal.app/metatrader/webrequest-metatrader-how-trade-sync-works

---


# WebRequest in MetaTrader - How Trade Sync Works

If you have tried to set up the Trader Journal EA and encountered errors in the MT4 Experts log mentioning "URL not allowed" or "WebRequest not enabled," this article explains what is happening and how to fix it.

---

## What Is WebRequest

WebRequest is a built-in function in MQL4 and MQL5 that allows Expert Advisors to send HTTP requests to external web servers.

In MQL4, the function signature looks like:
WebRequest(method, url, headers, timeout, data, result, result_headers)

The EA uses this function to POST your trade data (as JSON) to the Trader Journal API endpoint. Without WebRequest, the EA has no way to send data off your computer.

---

## Why WebRequest Is Disabled by Default

MetaTrader blocks WebRequest calls from EAs by default. This is a security measure designed to prevent malicious EAs from:

- Sending your account data to unknown servers without your knowledge
- Making unauthorized HTTP requests to external services
- Communicating with command-and-control servers in the case of malware EAs

The default-blocked state means no EA can make internet requests unless you explicitly permit it.

---

## How to Enable WebRequest

You whitelist specific URLs that you trust. The EA can then make requests to those URLs only.

**In MT4:**
1. Go to Tools > Options
2. Click the Expert Advisors tab
3. Check the checkbox "Allow WebRequest for listed URL"
4. In the URL list below, add the Trader Journal API endpoint (shown in your app's setup walkthrough)
5. Click OK

**In MT5:**
1. Go to Tools > Options
2. Click the Expert Advisors tab
3. Check "Allow WebRequest for listed URL"
4. Add the API endpoint URL
5. Click OK

After enabling, MT4/MT5 will allow the EA to send requests to that specific URL. No other URLs are affected.

---

## What the EA Sends to the Server

The EA sends HTTPS POST requests containing JSON-formatted trade data. A typical payload for a single closed trade looks like:

A JSON object with fields for ticket, symbol, type, open/close times and prices, volume, commission, swap, and profit.

The server receives this, authenticates via the API key in the request header, and stores the trade data linked to your journal account.

---

## The API Key in the Request Header

Every request from the EA includes your API key in the Authorization header. The server validates this key before processing any data. If the key is wrong or missing, the server returns an authentication error and the trade is not stored.

This is why configuring the correct API key in the EA's inputs is essential. A wrong key looks like a successful request from the EA's perspective (no network error) but the server rejects it.

---

## Checking Requests in the Experts Log

After enabling WebRequest and configuring the EA, the MT4/MT5 Experts tab shows the result of each sync request:

- Success messages confirm the data was received and stored
- Error messages include the HTTP status code and reason, which helps diagnose problems

HTTP 200 means success. HTTP 401 means authentication failed (wrong API key). HTTP 403 means forbidden. Any 4xx code indicates a client-side configuration issue.

---

Download Trader Journal and walk through the EA setup at android.traderjournal.app or ios.traderjournal.app.