Access to Nearmap imagery is limited to paying customers only. In order to get access to imagery APIs you can use HTTP Basic Authentication (aka Basic Auth). Basic Authentication is a HTTP standard for transmitting username/password credentials along with the request. For this reason, it is recommended to always use HTTPS to ensure all communication is encrypted, otherwise the credentials will be passed in plain text for all to see.
There are a number of ways to use Basic Authentication.
- Be prompted by Nearmap
If you’re using a browser, or another application (many GIS applications support this type of authentication), just make a request. For example, a tile request:
Note: ensure to set httpauth=true in the URL, or omit it entirely (the default value is true).
If you are not yet authorized (i.e. you don’t have an authentication token) you will be challenged by Nearmap. That just means you will be prompted for a username/password by the browser:
If successful this will result in a response from Nearmap that, along with the requested resource, will also set the authentication cookie nearmap_web3_app. This cookie can then be used by the browser on subsequent requests. Hence this is why you may not be prompted again for Basic Authentication. To reset your state just delete the nearmap_web3_app cookie, or try a private browsing mode (like Chrome’s Incognito mode).
- Request Authorization Header
If you’re not using a browser, for example making requests using a terminal applications like curl, then you can supply Basic Authentication via a request header.
Header Key: Authorization
Header Value: Basic <base64 encoded username:password>
Note: Note that the Header value is Authorization, not Authentication.
To generate the base64 encoded username/password create the string username:password (including the colon) and run it through a base64 encoder:
echo -n "username:password" | base64
$Text = “username:password”
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text)
Example: transmit username/password via Basic Authentication:
- Construct the base64 encoded username:password string:
Myusername:Mypassword -> TXl1c2VybmFtZTpNeXBhc3N3b3Jk
- Create a request header to send with the request.
Authorization: Basic TXl1c2VybmFtZTpNeXBhc3N3b3Jk
An example tile request made on a Linux terminal could look like:
curl -v "https://au.nearmap.com/maps/?hl=en&nml=V&version=2&x=120365&y=79062&z=17" -H "Authorization: Basic TXl1c2VybmFtZTpNeXBhc3N3b3Jk"