Page tree
Skip to end of metadata
Go to start of metadata

The following samples illustrate how to use the locations discovery service to obtain the locationCode from the service response. Use the locationCode to request data via the dataProductDelivery service.

 

 Get all Locations

This example returns all Locations and prints the results.

Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE'} # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE'} # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE'];			%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE")) #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get the location for a specific location code

This example returns the location with locationCode 'BACAX' and prints out the results. The locationCode filter is case sensitive and must match a valid locationCode exactly.

Parameters:

  • locationCode=BACAX
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
			'locationCode':'BACAX'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
			'locationCode':'BACAX'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile
        '&locationCode=BACAX'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.ca/Profile when logged in.
                      locationCode="BACAX"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations, including and below a location in the Oceans 2.0 GUI

This example returns all Locations including and below location 'NEP' ('Northeast Pacific') in the Oceans 2.0 Data Search Tree and prints out the results. The locationCode and includeChildren filters are case sensitive and must match exactly.

Parameters:

  • locationCode=NEP
  • includeChildren=true
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'locationCode':'NEP',
			'includeChidren':'true'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'locationCode':'NEP',
			'includeChidren':'true'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&locationCode=NEP' ...
        '&includeChildren=true'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
 library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      locationCode="NEP",
                      includeChildren="true"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations which have a certain word in the name

This example returns all Locations with 'underwater' as part of the name, and prints the results. The locationName filter is NOT case sensitive, so capitalized 'Underwater' will also be returned.

Parameters:

  • locationName=underwater
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'locationName':'underwater'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'locationName':'underwater'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&locationName=underwater'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
 library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      locationName="underwater"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations with instruments of a specific device category

This example returns all locations which have at least one instrument for the deviceCategoryCode 'ADCP150KHZ' and prints the results. The deviceCategoryCode filter is case sensitive and must match a valid deviceCategoryCode exactly. See deviceCategories service for further details.

Parameters:

  • deviceCategoryCode=ADCP150KHZ
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'deviceCategoryCode':'ADCP150KHZ'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'deviceCategoryCode':'ADCP150KHZ'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&deviceCategoryCode=ADCP150KHZ'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
 library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      deviceCategoryCode="ADCP150KHZ"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations with instruments that have a specific property

This example returns all Locations with at least one instrument that measures the property 'differentialtermperature' and prints the results. The propertyCode filter is case sensitive and must match a valid propertyCode exactly. See properties service for further details.

Parameters:

  • propertyCode=differentialtemperature
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'propertyCode':'differentialtemperature'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'propertyCode':'differentialtemperature'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&propertyCode=differentialtemperature'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
 library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      propertyCode="differentialtemperature"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations with instruments that have a specific device category and a specific property

This example returns all Locations with at least one instrument that has the device category 'CTD' and property 'pressure' and prints the results. The deviceCategoryCode filter is case sensitive and must match a valid deviceCategoryCode exactly. See deviceCategories service for further details. The propertyCode filter is case sensitive and must match a valid propertyCode exactly. See properties service for further details.

Parameters:

  • deviceCategoryCode=CTD
  • propertyCode=pressure
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'deviceCategoryCode':'CTD',
			'propertyCode':'pressure'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'deviceCategoryCode':'CTD',
			'propertyCode':'pressure'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&deviceCategoryCode=CTD' ...
        '&propertyCode=pressure'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      deviceCategoryCode="CTD",
                      propertyCode="pressure"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations where a specific device has been deployed

This example returns all locations where a device with the deviceCode 'NORTEKAQDPRO8398' has been deployed and prints the results. The deviceCode filter is case sensitive and must match a valid deviceCode exactly. See devices service for further details.

Parameters:

  • deviceCode=NORTEKAQDPRO8398
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'deviceCode':'NORTEKAQDPRO8398'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'deviceCode':'NORTEKAQDPRO8398'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&deviceCode=NORTEKAQDPRO8398'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      deviceCode="NORTEKAQDPRO8398"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations with instruments that support a specific data product code

This example returns all Locations with instruments that support the dataProductCode 'IBPP' ('Ice Buoy Profile Plots') and prints the results. The dataProductCode filter is case sensitive and must match a valid dataProductCode exactly. See dataProductCode service for further details.

Parameters:

  • dataProductCode=IBPP
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'dataProductCode':'IBPP'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'dataProductCode':'IBPP'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&dataProductCode=IBPP'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      dataProductCode="IBPP"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations with instruments deployed between two dates

This example returns all Locations with instruments that were deployed between 1 July 2010 and 30 June 2012, and prints the results. Both the dateFrom and dateTo must be included and be valid UTC date/time values in the format yyyy-MM-dd'T'HH:mm:ss.SSS'Z' and the dateFrom date/time must be before the dateTo date/time.

Parameters:

  • dateFrom=2010-07-01T00:00:00.000Z
  • dateTo=2012-06-30T23:59:59.999Z
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'dateFrom':'2010-07-01T00:00:00.000Z',
			'dateTo':'2012-06-30T23:59:59.999Z'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at http://data.oceannetworks.ca/Profile
			'dateFrom':'2010-07-01T00:00:00.000Z',
			'dateTo':'2012-06-30T23:59:59.999Z'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&dateFrom=2010-07-01T00:00:00.000Z' ...
        '&dateTo=2012-06-30T23:59:59.999Z'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      dateFrom="2010-07-01T00:00:00.000Z",
                      dateTo="2012-06-30T23:59:59.999Z"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get all locations with instruments deployed between two dates, with a sensor for a specific property

This example returns all Locations with instruments that were deployed between 1 July 2010 and 30 June 2011 and have a sensor for the propertyCode 'seawatertemperature', and prints the results. Both the dateFrom and dateTo must be included and be valid UTC date/time values in the format yyyy-MM-dd'T'HH:mm:ss.SSS'Z' and the dateFrom date/time must be before the dateTo date/time.

Parameters:

  • propertyCode=seawatertemperature
  • dateFrom=2010-07-01T00:00:00.000Z
  • dateTo=2012-06-30T23:59:59.999Z
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'propertyCode':'seawatertemperature',
			'dateFrom':'2010-07-01T00:00:00.000Z',
			'dateTo':'2011-06-30T23:59:59.999Z'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content,'utf-8')) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'get',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'propertyCode':'seawatertemperature',
			'dateFrom':'2010-07-01T00:00:00.000Z',
			'dateTo':'2011-06-30T23:59:59.999Z'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	locations = json.loads(str(response.content)) # convert the json response to an object
	for location in locations:
		print(location)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
MATLAB
url = ['https://data.oceannetworks.ca/api/locations' ...
        '?method=get' ...
        '&token=YOUR_TOKEN_HERE' ...						%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
        '&propertyCode=seawatertemperature' ...
        '&dateFrom=2010-07-01T00:00:00.000Z' ...
        '&dateTo=2012-06-30T23:59:59.999Z'];
    
request = matlab.net.http.RequestMessage;
uri = matlab.net.URI(url);
options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

response = send(request,uri,options);

if (response.StatusCode == 200)    % HTTP Status - OK
    locations = response.Body.Data;
    for i=1:numel(locations)
        location = locations(i);
        disp(location);
    end
elseif (response.StatusCode == 400) % HTTP Status - Bad Request
    disp(response.Body.Data.errors);
else % all other HTTP Statuses
    disp(char(response.StatusLine));
end
R
library(httr)
r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="get", 
                      token="YOUR_TOKEN_HERE", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      propertyCode="seawatertemperature",
                      dateFrom="2010-07-01T00:00:00.000Z",
                      dateTo="2012-06-30T23:59:59.999Z"))

if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    str(location)
  }
}
 Get location hierarchy including and below a specific location

This example returns the Location hierarchy from the 'MOBP' ('Mobile Platforms') node and below, and prints the locationCode and Name, indented for each tree level. If the locationCode parameter is excluded, the entire Oceans 2.0 Tree structure is returned.

Parameters:

  • locationCode=MOBP
Python 3.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'getTree',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'locationCode':'MOBP'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	print('Locations')
	locations = json.loads(str(response.content,'utf-8'))
	for location in locations:
		locationCode = location['locationCode']
		locationName = location['locationName']
		children = location['children']
		print('{0} - {1}'.format(locationCode,locationName))

		if (children):
			for child in children:
				getLocationChild(child,2)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content,'utf-8'))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
 
 
def getLocationChild(location,level):
	locationCode = location['locationCode']
	locationName = location['locationName']
	children = location['children']
	sTab = "  ".join(["" for r in range(0,level)])
	print('{0}{1} - {2}'.format(sTab,locationCode,locationName))
 
	if (children):
		for child in children:
			getLocationChild(child,level+1)
Python 2.x
import requests
import json
 
url = 'https://data.oceannetworks.ca/api/locations'
parameters = {'method':'getTree',
			'token':'YOUR_TOKEN_HERE', # replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
			'locationCode':'MOBP'}
 
response = requests.get(url,params=parameters)
 
if (response.ok):
	print('Locations')
	locations = json.loads(str(response.content))
	for location in locations:
		locationCode = location['locationCode']
		locationName = location['locationName']
		children = location['children']
		print('{0} - {1}'.format(locationCode,locationName))

		if (children):
			for child in children:
				getLocationChild(child,2)
else:
	if(response.status_code == 400):
		error = json.loads(str(response.content))
		print(error) # json response contains a list of errors, with an errorMessage and parameter
	else:
		print ('Error {} - {}'.format(response.status_code,response.reason))
 
 
def getLocationChild(location,level):
	locationCode = location['locationCode']
	locationName = location['locationName']
	children = location['children']
	sTab = "  ".join(["" for r in range(0,level)])
	print('{0}{1} - {2}'.format(sTab,locationCode,locationName))
 
	if (children):
		for child in children:
			getLocationChild(child,level+1)
MATLAB
getLocationsHierarchy()
 
function getLocationsHierarchy()
            
    url = ['https://data.oceannetworks.ca/api/locations?' ...
            '&method=getTree' ...
            '&token=YOUR_TOKEN_HERE'];							%replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
            '&locationCode=MOBP'];

    request = matlab.net.http.RequestMessage;
    uri = matlab.net.URI(url);
    options = matlab.net.http.HTTPOptions('ConnectTimeout',60);

    response = send(request,uri,options);

    if (response.StatusCode == 200)    % HTTP Status - OK
        locations = response.Body.Data;
        
        for i=1:numel(locations)
            location = locations(i);
            
            disp(sprintf('%s - %s',location.locationCode,location.locationName));
            
            if (numel(location.children) >= 1)
                for c=1:numel(location.children)
                    getLocationChild(location.children(c),1);
                end
            end
        end
    elseif (response.StatusCode == 400) % HTTP Status - Bad Request
        disp(response.Body.Data.errors);
    else % all other HTTP Statuses
        disp(char(response.StatusLine));
    end
end

function getLocationChild(location,level)
    sTab = '';
    for t=1:level
        sTab = sprintf('\t %s',sTab);
    end
    
    disp(sprintf('%s %s - %s',sTab, location.locationCode,location.locationName));
            
    if (numel(location.children) >= 1)
        for c=1:numel(location.children)
            getLocationChild(location.children(c),level + 1);
        end
    end
end
R
library(httr)


getChildLocation <- function(location,level){
  sTab = ""
  for (t in 1:level){
    sTab = sprintf("  %s",sTab)
  }
  
  cat(sprintf("%s%s - %s\n",sTab, location$locationCode,location$locationName))
  
  children=location$children
  newLevel=level+1
  for (child in children) {
    getChildLocation(child,newLevel)
  }
  return()
}


r <- GET("https://data.oceannetworks.ca/api/locations", 
         query = list(method="getTree", 
                      token="b6ede000-1865-4ac3-94ad-e87d8bdfd307", #>replace YOUR_TOKEN_HERE with your personal token obtained from the 'Web Services API' tab at https://data.oceannetworks.can/Profile when logged in.
                      locationCode="MOBP"))
if (http_error(r)) {
  if (r$status_code == 400){
    error = content(r)
    str(error)
  } else {
    str(http_status(r)$message)
  }
} else {
  locations = content(r)
  for (location in locations){
    cat(sprintf("%s - %s\n",location$locationCode,location$locationName))
    children = location$children
    for (child in children) {
      getChildLocation(child,1)
    }
  }
}

 

 

Please report all issues with the web services, documentation, samples and client libraries to the Oceans 2.0 Help Centre