API Response Formats (JSON & XML)
All IPGeolocation.io API endpoints support JSON and XML responses. JSON is the default response format. The only exception is the Get IP endpoint, which also supports plain-text output.
At a Glance
- Default: JSON
- XML:
output=xmlorAccept: application/xml/Accept: text/xml - If no output/Accept is set: response is JSON
- Get IP endpoint: returns public IP address, no auth, supports JSON/XML/plain text via
output
JSON (Default)
If you do not specify a response format, the API responds in JSON.
This is the recommended format for most integrations, SDK usage, and backend services.
This example looks up 1.1.1.1 and selects location.city . The ip field is always returned. The XML examples below use the same IP and field selection so you can compare the two formats.
curl -X GET 'https://api.ipgeolocation.io/v3/ipgeo?apiKey=API_KEY&ip=1.1.1.1&fields=location.city'1{
2 "ip": "1.1.1.1",
3 "location": {
4 "city": "South Brisbane"
5 }
6}XML
To request XML, use one of the two supported options below. Both return the same lookup as the JSON example, with Content-Type: application/xml and a LinkedHashMap root element.
1. Option 1: URL Parameter (output=xml)
Pass output=xml as a URL parameter.
curl -X GET 'https://api.ipgeolocation.io/v3/ipgeo?apiKey=API_KEY&ip=1.1.1.1&fields=location.city&output=xml'1<LinkedHashMap>
2 <ip>1.1.1.1</ip>
3 <location>
4 <city>South Brisbane</city>
5 </location>
6</LinkedHashMap>2. Option 2: Accept Header
Set the Accept HTTP header to application/xml or text/xml .
curl -X GET 'https://api.ipgeolocation.io/v3/ipgeo?apiKey=API_KEY&ip=1.1.1.1&fields=location.city' \
-H 'Accept: text/xml'1<LinkedHashMap>
2 <ip>1.1.1.1</ip>
3 <location>
4 <city>South Brisbane</city>
5 </location>
6</LinkedHashMap>Choosing a Response Format
Use the output query parameter or the request's Accept header to select a format. Use one selector, or keep both consistent. Check the response's Content-Type header before parsing its body.
| Format | Request selector | Response Content-Type |
|---|---|---|
| JSON | Default, output=json , or Accept: application/json | application/json |
| XML | output=xml , Accept: application/xml , or Accept: text/xml | application/xml |
| Plain text (Get IP only) | output=text | text/plain |
For JSON/XML selection on IP Geolocation ( /v3/ipgeo ) and Get IP ( /v3/getip ), the following conflicting selectors resolve according to Accept :
-
output=jsonwithAccept: application/xmlreturns XML. -
output=xmlwithAccept: application/jsonreturns JSON.
If output=xml returns JSON, check whether your client sends Accept: application/json . On these two endpoints, an unsupported output value such as output=yaml falls back to JSON when no explicit Accept header is set. Use the supported values above instead of relying on that fallback.
For Get IP plain text, use output=text . Setting Accept: text/plain alone does not select plain text. A request's Content-Type describes the body you send; use Accept to request a response format.
Get IP Endpoint (No Auth)
The Get IP endpoint returns the public IP address of the client where it is called. If called from your server, it returns the server IP. If called from your website (JavaScript), it returns the visitor's IP address. This endpoint does not require authentication and can be used without creating an account.
The address 1.1.1.1 in the response examples is illustrative. Your response contains the public IP address of the client making the request.
1. Output Parameter
The optional output query parameter controls the response format:
-
output=json(default): JSON -
output=xml: XML -
output=text: plain text
2. JSON Response (Default)
Response header: Content-Type: application/json .
curl -X GET 'https://api.ipgeolocation.io/v3/getip'1{
2 "ip": "1.1.1.1"
3}3. XML Response
Response header: Content-Type: application/xml .
curl -X GET 'https://api.ipgeolocation.io/v3/getip?output=xml'1<LinkedHashMap>
2 <ip>1.1.1.1</ip>
3</LinkedHashMap>4. Plain Text Response
Response header: Content-Type: text/plain .
curl -X GET 'https://api.ipgeolocation.io/v3/getip?output=text'11.1.1.1Frequently Asked Questions
output=xml or set Accept: application/xml or Accept: text/xml .