# NetSuite TransactionLine API Test Queries

## 📋 **Postman Test Setup**

### **Base Configuration**
- **Method**: POST
- **URL**: `https://5424079-sb1.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql`
- **Headers**:
  - `Content-Type: application/json`
  - `Authorization: OAuth oauth_consumer_key="YOUR_CONSUMER_KEY", oauth_token="YOUR_TOKEN", oauth_signature_method="HMAC-SHA256", oauth_timestamp="TIMESTAMP", oauth_nonce="NONCE", oauth_version="1.0", oauth_signature="YOUR_SIGNATURE"`

## 🎯 **Test Queries (Progressive Complexity)**

### **Query 1: COUNT Query (Known to Work)**
This is the query that succeeded and returned 35,633,287 records:

```json
{
  "q": "SELECT COUNT(*) as total FROM transactionline WHERE transactionline.mainline = 'F'"
}
```

**Expected**: Fast response (~4 minutes based on logs)
**Purpose**: Confirm API connectivity

---

### **Query 2: Simple SELECT with LIMIT (Current Hanging Query)**
This is the exact query our system is trying to execute:

```json
{
  "q": "SELECT transactionline.* FROM transactionline INNER JOIN transaction ON transactionline.transaction = transaction.ID WHERE transactionline.mainline = 'F' LIMIT 1000 OFFSET 0"
}
```

**Expected**: This is currently hanging for 20+ minutes
**Purpose**: Test if ANY data retrieval works

---

### **Query 3: Minimal Fields Test**
Test with just essential fields to reduce payload:

```json
{
  "q": "SELECT transactionline.id, transactionline.transaction, transactionline.quantity FROM transactionline WHERE transactionline.mainline = 'F' LIMIT 10 OFFSET 0"
}
```

**Expected**: Should be faster if it's a data volume issue
**Purpose**: Test if specific field selection helps

---

### **Query 4: No JOIN Test**
Test without the INNER JOIN to isolate the issue:

```json
{
  "q": "SELECT transactionline.id, transactionline.transaction, transactionline.quantity FROM transactionline WHERE transactionline.mainline = 'F' LIMIT 10 OFFSET 0"
}
```

**Expected**: Should be faster without JOIN complexity
**Purpose**: Test if JOIN is causing the hang

---

### **Query 5: Different OFFSET Test**
Test if higher offsets work (maybe offset 0 is problematic):

```json
{
  "q": "SELECT transactionline.id, transactionline.transaction FROM transactionline WHERE transactionline.mainline = 'F' LIMIT 10 OFFSET 1000"
}
```

**Expected**: Test if offset position matters
**Purpose**: See if certain data ranges are corrupted

---

### **Query 6: Alternative WHERE Clause**
Test with a different filter approach:

```json
{
  "q": "SELECT transactionline.id, transactionline.transaction FROM transactionline WHERE transactionline.mainline = 'F' AND transactionline.id IS NOT NULL LIMIT 10"
}
```

**Expected**: Test if mainline='F' filter is the issue
**Purpose**: Alternative filtering approach

## 🔍 **Diagnostic Questions**

Based on the test results, we can determine:

| **Query Result** | **Diagnosis** | **Next Action** |
|------------------|---------------|-----------------|
| **Query 1 ✅, Query 2 ❌** | Full SELECT with JOIN hangs | Try Query 3 (minimal fields) |
| **Query 2 ❌, Query 3 ✅** | Too many fields selected | Reduce field selection in app |
| **Query 2 ❌, Query 4 ✅** | INNER JOIN causing issue | Remove JOIN or optimize |
| **Query 2 ❌, Query 5 ✅** | Offset 0 has corrupt data | Start import from higher offset |
| **All Queries ❌** | NetSuite SELECT completely broken | Contact NetSuite support |

## 🚀 **Expected Outcome**

If **Query 2 hangs in Postman** (matching our app experience):
- ✅ **Confirms the issue is NetSuite, not our application**
- ✅ **Validates that proactive batch cancellation is the correct solution**
- ✅ **Proves our timeout detection will work when implemented**

If **Query 2 succeeds in Postman**:
- 🔍 **Issue may be OAuth/authentication related**
- 🔍 **Could be a concurrent request limit issue**
- 🔍 **May need to investigate our request formatting**

## 📊 **Test Timeline Expectations**

Based on our logs:
- **COUNT Query**: ~4 minutes response time
- **Data Queries**: 20+ minutes and still hanging
- **Expected Detection**: Our system will trigger cancellation when these return empty after 15+ seconds

**This test will validate whether the 20+ minute hang is a NetSuite API limitation or an application issue.**
