Skip to content

Commit

Permalink
Fixes the UK Met Office Datahub provider (#3499)
Browse files Browse the repository at this point in the history
Fixes #3384

Changed the UKMetOfficeDataHub provider to the new API structure as per
the documentation.

API Base URL updated.
Header information amended to the correct key name.
API Secret no longer required so removed.

Changelog updated to reflect the change.
  • Loading branch information
jargordon committed Jul 7, 2024
1 parent 3b22622 commit 4d14f4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ _This release is scheduled to be released on 2024-10-01._
### Fixed

- Fixed `checks` badge in README.md
- [weather] Fixed issue with the UK Met Office provider following a change in their API paths and header info.

## [2.28.0] - 2024-07-01

Expand Down
13 changes: 5 additions & 8 deletions modules/default/weather/providers/ukmetofficedatahub.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
* This provider requires longitude/latitude coordinates, rather than a location ID (as with the previous Met Office provider)
* Provide the following in your config.js file:
* weatherProvider: "ukmetofficedatahub",
* apiBase: "https://api-metoffice.apiconnect.ibmcloud.com/metoffice/production/v0/forecasts/point/",
* apiBase: "https://data.hub.api.metoffice.gov.uk/sitespecific/v0/point/",
* apiKey: "[YOUR API KEY]",
* apiSecret: "[YOUR API SECRET]",
* lat: [LATITUDE (DECIMAL)],
* lon: [LONGITUDE (DECIMAL)]
*
Expand All @@ -38,14 +37,13 @@ WeatherProvider.register("ukmetofficedatahub", {

// Set the default config properties that is specific to this provider
defaults: {
apiBase: "https://api-metoffice.apiconnect.ibmcloud.com/metoffice/production/v0/forecasts/point/",
apiBase: "https://data.hub.api.metoffice.gov.uk/sitespecific/v0/point/",
apiKey: "",
apiSecret: "",
lat: 0,
lon: 0
},

// Build URL with query strings according to DataHub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api)
// Build URL with query strings according to DataHub API (https://datahub.metoffice.gov.uk/docs/f/category/site-specific/type/site-specific/api-documentation#get-/point/hourly)
getUrl (forecastType) {
let queryStrings = "?";
queryStrings += `latitude=${this.config.lat}`;
Expand All @@ -58,12 +56,11 @@ WeatherProvider.register("ukmetofficedatahub", {

// Build the list of headers for the request
// For DataHub requests, the API key/secret are sent in the headers rather than as query strings.
// Headers defined according to Data Hub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api)
// Headers defined according to Data Hub API (https://datahub.metoffice.gov.uk/docs/f/category/site-specific/type/site-specific/api-documentation#get-/point/hourly)
getHeaders () {
return {
accept: "application/json",
"x-ibm-client-id": this.config.apiKey,
"x-ibm-client-secret": this.config.apiSecret
apikey: this.config.apiKey
};
},

Expand Down

0 comments on commit 4d14f4a

Please sign in to comment.