URL Encoding - Critical Knowledge¶
Most Common Mistake
URL encoding is the #1 source of errors when using the Danish Parliament API. Failure to properly encode URLs will result in HTTP 400 errors or unexpected results.
The Golden Rule¶
Always use %24 instead of $ in OData query parameters.
| L Wrong | ✅ Correct | Result |
|---|---|---|
?$top=5 |
?%24top=5 |
Works |
?$filter=id eq 1 |
?%24filter=id%20eq%201 |
Works |
?$expand=Aktør |
?%24expand=Akt%C3%B8r |
Works |
Why This Matters¶
OData uses the $ character for system query options like $top, $filter, etc. However, $ has special meaning in URLs and shells, so it must be URL encoded as %24.
Complete Encoding Reference¶
Basic Characters¶
Danish Characters¶
Real Examples¶
Basic Queries¶
Text Filtering¶
Complex Queries¶
Danish Text Searches¶
Programming Language Examples¶
Python¶
import urllib.parse
# Proper URL encoding
query = "$filter=substringof('klima', titel)&$top=5"
encoded_query = urllib.parse.quote(query, safe🔧&🔧)
url = f"https://oda.ft.dk/api/Sag?{encoded_query}"
# Or use requests which handles encoding
import requests
params = {
'$filter': "substringof('klima', titel)",
'$top': 5
}
response = requests.get('https://oda.ft.dk/api/Sag', params=params)
JavaScript¶
// Proper URL encoding
const params = new URLSearchParams({
'$filter': "substringof('klima', titel)",
'$top': 5
});
const url = `https://oda.ft.dk/api/Sag?${params}`;
// Or use encodeURIComponent for manual encoding
const filter = encodeURIComponent("substringof('klima', titel)");
const url2 = `https://oda.ft.dk/api/Sag?%24filter=${filter}&%24top=5`;
curl in Shell Scripts¶
#!/bin/bash
# Proper escaping in shell scripts
FILTER="year(opdateringsdato) eq 2025"
curl "https://oda.ft.dk/api/Sag?%24filter=${FILTER// /%20}&%24top=10"
Common Encoding Mistakes¶
1. Missing Dollar Sign Encoding¶
# L Will cause HTTP 400
curl "https://oda.ft.dk/api/Sag?$top=5"
# ✅ Correct
curl "https://oda.ft.dk/api/Sag?%24top=5"
2. Missing Space Encoding¶
# L Malformed query
curl "https://oda.ft.dk/api/Sag?%24filter=id eq 1"
# ✅ Spaces encoded
curl "https://oda.ft.dk/api/Sag?%24filter=id%20eq%201"
3. Danish Characters¶
# L May cause issues
curl "https://oda.ft.dk/api/Aktør?%24filter=substringof('ø',navn)"
# ✅ Properly encoded
curl "https://oda.ft.dk/api/Akt%C3%B8r?%24filter=substringof('%C3%B8',navn)"
4. Complex Boolean Logic¶
# L Parentheses not encoded
curl "https://oda.ft.dk/api/Sag?%24filter=(typeid eq 3) and (year(opdateringsdato) gt 2020)"
# ✅ Complete encoding
curl "https://oda.ft.dk/api/Sag?%24filter=%28typeid%20eq%203%29%20and%20%28year%28opdateringsdato%29%20gt%202020%29"
Testing Your Encoding¶
Use these test queries to verify your encoding works:
Test 1: Basic Query¶
Test 2: Text Filter¶
curl "https://oda.ft.dk/api/Sag?%24filter=substringof('forslag',titel)&%24top=1" | jq '.value | length'
# Expected: 1 (if results exist)
Test 3: Date Filter¶
curl "https://oda.ft.dk/api/Sag?%24filter=year%28opdateringsdato%29%20eq%202025&%24top=1" | jq '.value | length'
# Expected: 1 (if results exist)
Error Symptoms¶
If your URLs aren't properly encoded, you'll see:
HTTP 400 Bad Request¶
Empty HTML Response¶
<!DOCTYPE html>
<html>
<head><title>400 Bad Request</title></head>
<body>
<h1>400 Bad Request</h1>
</body>
</html>
Shell Errors¶
Quick Reference Table¶
| Character/Sequence | Encoding | Example Usage |
|---|---|---|
$top=5 |
%24top=5 |
Pagination |
$filter= |
%24filter= |
Filtering |
id eq 1 |
id%20eq%201 |
Filter condition |
substringof('text', field) |
substringof('text',field) |
Text search |
year(date) eq 2025 |
year%28date%29%20eq%202025 |
Date functions |
(condition1) and (condition2) |
%28condition1%29%20and%20%28condition2%29 |
Boolean logic |
Tools for URL Encoding¶
Online Tools¶
Command Line Tools¶
# Python one-liner
python3 -c "import urllib.parse; print(urllib.parse.quote(input()))"
# Node.js one-liner
node -e "console.log(encodeURIComponent(process.argv[1]))" "your text here"
Remember: When in doubt, encode everything! It's better to over-encode than under-encode with this API.