Blog / How-to
How to call an oil price API in Postman
In Postman, create a GET request to https://api.oilpriceapi.com/v1/prices/latest with the query parameter by_code=WTI_USD, and send your key in an Authorization header whose value is Token, a space, then the key. Postman's API Key auth type does this for you. Press Send and the latest WTI price comes back as JSON.
If you would rather start from every endpoint at once, import our Postman collection (step 5). It uses the same header.
By OilPriceAPI · Published · Requests and test script run against the live API on Nov 27, 2026 with Newman 6, the Postman command-line runner
The workflow
Environment variable apiKey (type: secret)
Select the environment in the top-right picker.
GET /v1/prices/latest?by_code=WTI_USD,BRENT_CRUDE_USD
Authorization: Token {{apiKey}} via the API Key auth type.
Send and read data.prices and observed_at
Post-response test script
Fails the run if the response or the key changes.
Save to a collection and run it with Newman
The same collection works as a CI smoke test.
1. Store your key in an environment
Create an environment (Environments, then +), add a variable named apiKey, set its type to secret, and paste your key as the value. Select that environment in the top-right picker. The request then refers to {{apiKey}}, so the key never sits in the request itself.
2. Build the request
| Field | Value |
|---|---|
| Method | GET |
| URL | https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD,BRENT_CRUDE_USD |
| Authorization tab: Auth Type | API Key |
| Authorization tab: Key | Authorization |
| Authorization tab: Value | Token {{apiKey}} |
| Authorization tab: Add to | Header |
Typing the URL fills the Params tab with by_code. Put up to 20 codes in it, separated by commas; they count as one request. Always pass by_code: without it the endpoint returns Brent. If you prefer the Headers tab, add a header with key Authorization and value Token {{apiKey}}; it sends the same thing. The request is the same as this curl command:
curl "https://api.oilpriceapi.com/v1/prices/latest?by_code=WTI_USD,BRENT_CRUDE_USD" \
-H "Authorization: Token YOUR_API_KEY"The value must start with Token and a space. When we sent the bare key on Nov 27, 2026, the API answered 401 UNAUTHORIZED.
3. Read the response
{
"status": "success",
"data": {
"prices": [
{
"code": "WTI_USD",
"price": <number>,
"currency": "USD",
"observed_at": "<UTC timestamp>",
...
},
{ "code": "BRENT_CRUDE_USD", ... }
],
"missing": [],
"metadata": { ... }
}
}Two or more codes come back in data.prices, with any code that had no price listed in data.missing. A single code comes back as a flat data object instead. observed_at is when the source observed the price, in UTC. The Headers tab of the response shows your quota: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset and X-RateLimit-Window.
4. Add a test script
Paste this into the request's Scripts tab, under Post-response. Postman runs it after every Send and shows the results in the Test Results tab, so a changed response or an expired key shows up as a failed test. The script expects the two-code URL from step 2, because it reads data.prices.
pm.test("status is 200", () => pm.response.to.have.status(200));
const prices = pm.response.json().data.prices;
pm.test("one row per code", () =>
pm.expect(prices.map(p => p.code)).to.have.members(["WTI_USD", "BRENT_CRUDE_USD"]));
pm.test("prices are numbers", () =>
prices.forEach(p => pm.expect(p.price).to.be.a("number")));
console.log("remaining this window:", pm.response.headers.get("X-RateLimit-Remaining"));We ran this request and script with Newman 6 against the live API on Nov 27, 2026: 200, all three tests passed, and the remaining count printed to the console. Newman runs the same collection format from a terminal or CI job, so a saved collection doubles as a smoke test.
5. Or import the full collection
In Postman choose Import, then paste this link: https://www.oilpriceapi.com/OilPriceAPI.postman_collection.json. The collection has 43 requests across prices, futures, storage, marine fuels, rig counts and webhooks. It defines two collection variables: baseUrl, already set to https://api.oilpriceapi.com, and apiKey, left empty. Fill in apiKey on the collection's Variables tab, or leave it empty and select the environment from step 1. The 41 authenticated requests send Authorization: Token {{apiKey}}; the 2 demo requests need no key. Its "Get latest price for a commodity" request returned 200 when we ran it with Newman on Nov 27, 2026.
6. What each error means
| Status | Code | Cause | What to do |
|---|---|---|---|
| 401 | UNAUTHORIZED | The header is missing, the key is wrong, or the value lacks the "Token " prefix | Check the Authorization tab and that the environment holding apiKey is selected |
| 400 | invalid_code | A code in by_code does not exist | Read data.suggestions in the response; it lists the closest real codes |
| 429 | RATE_LIMIT_EXCEEDED | More than 60 requests in one 60-second window | Wait the Retry-After seconds; slow the Collection Runner with a delay |
| 402 | PAYMENT_REQUIRED or MONTHLY_QUOTA_EXCEEDED | The daily (Free) or monthly (paid) quota is used up | Resending will not help until the quota resets |
We triggered the 401 and 400 rows against the live API on Nov 27, 2026; a typo of WTI_US returned 400 with WTI_USD among the suggestions. Every limit and error code is listed in the rate limiting guide. The Collection Runner sends requests back to back, and each one counts against your quota, so add a delay before running a large collection many times.
Related guides
- Quick start (docs): get a key and make the first request.
- Testing guide (docs): testing an integration against the API.
- Python oil price API tutorial: the same request in code, once it works in Postman.
- How to get oil prices in R: the same request with httr2.
- How to cache OilPriceAPI requests: batching, ETags and the rate-limit headers.
Try it with your own key
New accounts get a 7-day trial with 10,000 requests and no credit card. After that, the Free plan is 50 requests/day. The Developer plan is $19/month for 10,000 requests/month.
Sources
- Live calls to /v1/prices/latest from Newman 6, Nov 27, 2026: success, missing Token prefix and an unknown code.
- OilPriceAPI.postman_collection.json as served on Nov 27, 2026.
- docs.oilpriceapi.com/guides/rate-limiting: limits and error codes, read Nov 26, 2026.