This is what I am getting:
This is a known nuance with Acumatica’s Contract-Based REST API (CBAPI).
🔍 The Core Issue:
You are using valid OData-style parameters ($orderby, $top), but those do not work reliably in CBAPI, especially for ordering by system-generated fields like CreatedDateTime or LastModifiedDateTime. Here’s why:
📌 CBAPI does not fully support OData query parameters like $orderby or $top, even if it appears to accept them silently. These parameters are not guaranteed to be parsed or respected unless the endpoint is explicitly built to do so.
This is documented behavior, and Acumatica support confirms that only OData endpoints support $orderby, $top, $filter reliably.
✅ What You Can Do Instead (CBAPI-compatible)
Since you’re restricted to CBAPI, here’s the correct approach:
✅ Option 1:
Filter on CreatedDateTime Manually
Because CBAPI returns unordered data, you’ll need to:
-
Retrieve a small page of records
-
Manually find the oldest by CreatedDateTime
Example request:
POST /entity/Default/23.200.001/JournalTransaction
{
"pageSize": 100,
"fields": {
"ReferenceNbr": {},
"CreatedDateTime": {}
}
}
Then in your client code:
oldest = min(results, key=lambda x: x['CreatedDateTime'])
⚠️ If there are many pages, you will need to loop through them.
✅ Option 2:
Create a Custom Endpoint That Supports Sorting
If you have admin access, this is the most maintainable method:
-
Go to: Web Services Endpoints (SM.20.20.60)
-
Clone the default Default/23.200.001
-
Add a new custom endpoint method:
-
Publish the endpoint
-
Use this new endpoint in your REST call — no $orderby needed
✅ Option 3:
Create a Generic Inquiry (GI) and Expose via OData
If you’re allowed to use OData GIs, you can:
-
Build a GI on JournalTransaction
-
Sort by CreatedDateTime ASC
-
Publish to OData
-
Use:
/OData/YourGI?$top=1
⚠️ You mentioned OData is not allowed, so this may be blocked in your environment.
🛠️ TL;DR Fix Summary:
| Task | Status in CBAPI | Workaround |
|---|
| $orderby (CreatedDateTime) | ❌ Not supported reliably | Use paging + client-side sort |
| $top=1 | ❌ Ignored unless combined with sort | Use paging manually |
| Custom endpoint with sort | ✅ Works | Use custom endpoint + sorting |
| OData GI | ✅ Works | Only if OData is permitted |
✅ Recommendation
If you cannot modify endpoints, your only safe solution is: