SAP’s API returns 200. Your OData connector can still lose data
Metadata is only what a service claims about itself; a handful of test calls before coding shows which claims a connector can rely on.

In brief
- $metadata is the service's own declaration; the real behavior of each query option still has to be tested on the client's system.
- With V2, follow __next to the last page, keep the link intact and convert /Date(...)/ explicitly.
- Before coding, establish whether the API is published, whether it is still supported and whether policy allows your use.
In SAP Gateway, $top and $skip work only if the developer of the service has implemented them. SAP Learning’s documentation says so explicitly, and says much the same about $orderby and $inlinecount. A syntactically correct URL therefore does not guarantee that you receive the slice of data you asked for.
FDEs know the situation well: the client sends a URL, a technical account and the words “It’s a standard OData API.” If you write the paging loop straight away, the connector may read the same page over and over, or stop at the first page without reporting an error.
A safer approach is to spend the first session reading the service as you would a contract, then testing each clause. The result should be a one-page profile clear enough for someone else to write the connector without guessing.
Start at the root URL
The OData 4.01 standard requires a service to return its service document from the root URL. Also under 4.01, you retrieve the metadata document, which describes the data model, by appending $metadata to that root. With an unfamiliar service, try these two calls before any business endpoint.
GET /service-root/
GET /service-root/$metadata
Mind the version: both rules come from 4.01, while the running example below uses V2. With a V2 service, treat the two calls as a first test and record exactly what the server returns.
If the client runs SAP Gateway but does not know which services it has, ask for access to the service catalog. The NetWeaver 7.5 documentation says this catalog lists every service available on the Gateway system, at the path /sap/opu/odata/iwfnd/CATALOGSERVICE/.
When you open $metadata, don’t read it from top to bottom. Find EntityContainer first: it declares the entity sets and any function or action imports. SAP’s tutorial treats it as a machine-readable overview of the whole service.
Then choose the one entity set that the client’s problem requires. Trace its data type and note the key, the date fields and the associations. The rest can wait.
Read one entity set thoroughly
Say the client wants to synchronize 250 purchase orders for company 1000. The V2 metadata below is abridged for this hypothetical example, and the names are invented.
<EntitySet Name="PurchaseOrders"
EntityType="DEMO.PurchaseOrder"
sap:pageable="true" />
<EntityType Name="PurchaseOrder">
<Key><PropertyRef Name="OrderId" /></Key>
<Property Name="OrderId" Type="Edm.String" />
<Property Name="CompanyCode" Type="Edm.String"
sap:required-in-filter="true" />
<Property Name="CreatedAt" Type="Edm.DateTime" />
</EntityType>
The sap: prefix marks SAP’s additions to OData V2 that describe query rules. sap:required-in-filter flags a field that must appear in $filter, while sap:pageable concerns support for $top and $skip. For other fields, check sap:filterable as well.
This snippet already yields a design decision: the connector must know the list of company codes before it reads any orders. The question for the client is: “Which company codes are in scope, and who will tell us when a new one is added?” Skip it, and the next expansion could leave out an entire business unit.
Before making test calls, ask two more things. The first is how long the API will be supported: SAP’s support article on the Purchase Order API says the V2 version was deprecated starting with release 2308, although it was still usable at that point.
The second is whether your use is allowed. According to an ISMG article from May 2026, SAP’s API Policy permits only published APIs and restricts integration with generative, autonomous or semi-autonomous AI. The text may have been revised since, so ask the client to confirm the current version and its exceptions.
Turn claims into tests
Test calls come once permitted use is clear. They are needed because the service publishes the annotations, but the code behind it determines the results. Run them in a test environment, on a small set that business staff can verify. Change one factor at each step so you know which one caused a failure.
| Test call | Expected result | If the result differs |
|---|---|---|
$filter=CompanyCode eq '1000' |
Every row belongs to company 1000 | Stop and ask the service owner about the filter |
Add $top=5 |
At most 5 rows | Don’t rely on $top to limit load |
Keep $top=5, add $orderby=OrderId |
First 5 keys of the sample list | Don’t rely on the server’s ordering |
Add $skip=5 |
Next 5 keys in the sample list | Don’t page with $skip |
Remove $filter |
You know exactly how the service refuses | Record both the HTTP status code and the error body |
Say the sample list is sorted by key and the first group runs from PO001 to PO005. If the call with $skip=5 still returns PO001 to PO005, a loop that keeps increasing $skip will only receive those same five orders again. A test that checks only for status 200 will miss the bug; a test that compares keys will catch it.
When you report back to the SAP team, bring evidence and a question: “With the same filter, two $skip values return the same five keys; does the service implement this option?” The recipient can reproduce the problem immediately, and the conversation does not turn into an argument over who is at fault.
150 orders lost, no errors logged
A service can also split results into pages on its own. In OData V2 JSON, the list sits in results inside the outer d wrapper; a __next pair signals that this is only part of the result and carries the URI of the next part.
In the 250-order example, if the server returns 100 at a time, you need three pages: 100, 100 and 50. A connector that reads only the results of the first page gets 40% and leaves 150 orders behind. The program still finishes, and the log stays clean.
The minimal reader below follows the server’s links and stops if a URL repeats. The session object is an authenticated HTTP session.
from urllib.parse import urljoin
def read_all(session, url):
seen = set()
while url:
if url in seen:
raise RuntimeError("Repeated next link")
seen.add(url)
response = session.get(
url,
headers={"Accept": "application/json"},
timeout=30,
)
response.raise_for_status()
data = response.json()["d"]
yield from data["results"]
next_url = data.get("__next")
url = urljoin(response.url, next_url) if next_url else None
Don’t extract $skiptoken and build a new URL yourself. The 4.01 standard requires clients to use the next link as is, without inferring anything from its contents, and forbids them from constructing their own queries with $skiptoken. Applying the same discipline to V2 is the prudent choice.
If you use a library, read up on its default behavior before wrapping another loop around it. SAP Cloud SDK for Java, for example, fetches every page automatically when it encounters server-side paging.
Dates and writes need their own tests
V2 JSON represents Edm.DateTime as /Date(<ticks>)/, where ticks is the number of milliseconds since January 1, 1970. /Date(1767225600000)/ therefore converts to 00:00 on January 1, 2026. Write a converter that raises an error on unfamiliar formats, then ask the client which business time zone the field uses.
import re
from datetime import datetime, timedelta
def parse_v2_datetime(value):
match = re.fullmatch(r"/Date\((-?\d+)\)/", value)
if match is None:
raise ValueError(f"Unexpected V2 date: {value!r}")
return datetime(1970, 1, 1) + timedelta(milliseconds=int(match[1]))
Writes also require handling the CSRF token, which SAP Gateway uses to protect requests that modify data. You send X-CSRF-Token: Fetch in a GET, receive a token tied to a cookie, then send the token when you write. Use the same HTTP session so the cookie is kept; if the CSRF check fails, the server returns 403.
On a 403, check the token and cookie first, but don’t conclude that every 403 is a CSRF problem. Account permissions are another hypothesis to rule out. An endless retry loop only makes the log longer.
What a one-page profile looks like
For the same 250 orders, the profile could be filled in as follows; all results are invented. Each line states something observed or something still to be asked, so whoever writes the code knows what they can rely on.
SERVICE PROFILE: PurchaseOrders (OData V2, test environment)
Key OrderId (Edm.String)
Required filter CompanyCode; current scope: 1000
Service declares sap:pageable="true"
Tested
$filter Pass: every row belongs to company 1000
$top=5 Pass: 5 rows
$orderby Pass: PO001-PO005, matches sample list
$skip=5 MISMATCH: still returns PO001-PO005
No $filter Refused; HTTP code and error body saved
Paging Via __next: 100 + 100 + 50
Reconciliation 250 unique keys, matches client-confirmed count
Dates CreatedAt as /Date(ticks)/; time zone unknown
Writes Out of scope, CSRF not tested
Decision Do not use $skip; follow __next only
Open questions
1. Does the service implement $skip? SAP team
2. Which time zone does CreatedAt use? Business
3. Who reports new company codes? Business
4. Is there a V4 version, when to move? SAP team
5. Does API policy allow this use? Client, in writing
The two most valuable lines are MISMATCH and Decision. The service declares pageable and the test shows otherwise, so the connector drops $skip and follows __next. The next person to read the profile sees the reason at once.
Four mistakes to stop in code review
The first mistake is trusting an annotation without testing it. The next is checking the row count of the first page and calling it the total; the safeguard is to reconcile the number of unique keys with a figure confirmed by the client.
The other two appear under time pressure: constructing your own next link and guessing what a date means. In review, insist on tests for the last page, duplicate keys, repeated links and unfamiliar date values. Perfect sample data can hide all four mistakes.
This skill is also easy to demonstrate in a job search. If a posting mentions ERP integration, REST APIs or data pipelines, prepare a repo with sample metadata, paging tests and a record of your assumptions. On your résumé, name the bug you prevented and how you verified it; don’t just write “knows OData.”
This week, give your profile to a colleague who has never seen the API. Ask them to write the first request and explain how they would know that all the data has been read. The first question they have to ask marks the spot where your connector is guessing.
Was this article useful?
Thanks for the feedback!
10 sources
- OData Version 4.01. Part 1: Protocol (OASIS Standard) · 2020-04-23
- Learn how to read OData metadata documents (SAP Developers)
- SAP Annotations for OData Version 2.0
- SAP Gateway Catalog Service (SAP Help Portal, NetWeaver 7.5)
- Performing OData Queries (SAP Learning)
- OData Version 2.0: JSON Format
- Cross-Site Request Forgery Protection (SAP Gateway, SAP Help Portal)
- Use the OData v2 Type-safe Client API (SAP Cloud SDK)
- 3365110 - Deprecation of Purchase Order API (OData V2) since CE 2308
- Explained: Why SAP Rewrote Its Third-Party API Policy · 2026-05-21