Skip to content

fix(emissions): update eMapsZonesResponse to match current Electricity Maps API#468

Merged
mahendrapaipuri merged 1 commit intoceems-dev:mainfrom
samoz83:fix/emaps-zones-response-type
Feb 25, 2026
Merged

fix(emissions): update eMapsZonesResponse to match current Electricity Maps API#468
mahendrapaipuri merged 1 commit intoceems-dev:mainfrom
samoz83:fix/emaps-zones-response-type

Conversation

@samoz83
Copy link
Contributor

@samoz83 samoz83 commented Feb 25, 2026

Fixes #467

Problem

The Electricity Maps /v3/zones endpoint has changed its response schema. Zone objects now contain non-string typed fields:

Field Old type New type
subZoneKeys did not exist / string []string (array)
isCommerciallyAvailable did not exist bool
zoneParentKey string string | null
tier did not exist string | null

The current type eMapsZonesResponse is defined as map[string]map[string]string, so json.Unmarshal fails when it encounters these non-string values: json: cannot unmarshal array into Go value of type string

This prevents ceems_exporter from starting when the [maps emissions provider is enabled.

Changes

  • pkg/emissions/types.go: Replaced eMapsZonesResponse from map[string]map[string]string to map[string]eMapsZoneDetails, adding a new eMapsZoneDetails struct that properly models the current API response.
  • pkg/emissions/emaps.go: Updated zone iteration to access struct fields (details.CountryName, details.ZoneName) instead of map indexing.
  • pkg/emissions/emaps_test.go: Updated TestNewEMapsProvider to use the new eMapsZoneDetailsstruct.

Testing

All existing emissions tests pass and ceems_exporter runs:

=== RUN TestEMapsDataProvider 
--- PASS 
=== RUN TestEMapsDataProviderError 
--- PASS 
=== RUN TestNewEMapsProvider 
--- PASS
=== RUN TestNewEMapsProviderFail 
--- PASS 
=== RUN TestEMapsAPIRequest 
--- PASS 
=== RUN TestEMapsAPIRequestFail 
--- PASS 
=== RUN TestEMapsAPIRequestZones 
--- PASS

…y Maps API

The /v3/zones endpoint now returns non-string typed fields (arrays,booleans, nullable strings) which cannot be unmarshaled into map[string]map[string]string. Replace with a proper struct.
@mahendrapaipuri
Copy link
Collaborator

Thanks a lot @samoz83 for the PR. Really appreciate it!! Could you confirm me that this patch works as expected for you? If so, I will cut a release with this PR.

Cheers!!

@samoz83
Copy link
Contributor Author

samoz83 commented Feb 25, 2026

Yep, I can confirm that my node is now running the exporter and not failing to start due to the unmarshal array issue and pulling in emaps data:
ceems_emissions_gCo2_kWh{country="Great Britain",country_code="GB",provider="emaps",provider_name="Electricity Maps"} 165

@mahendrapaipuri
Copy link
Collaborator

Awesome @samoz83

Cheers again for the PR. Let me merge it and make a new release!

@mahendrapaipuri mahendrapaipuri merged commit 4db3fb8 into ceems-dev:main Feb 25, 2026
14 checks passed
@mahendrapaipuri
Copy link
Collaborator

Between, are you using CEEMS in production @samoz83 ? If so, could I add that to the list of adopters?

Cheers!!

@samoz83 samoz83 deleted the fix/emaps-zones-response-type branch February 25, 2026 21:54
@samoz83
Copy link
Contributor Author

samoz83 commented Feb 25, 2026

@mahendrapaipuri Sure, we are using it in production on our AI@Surrey cluster at the University of Surrey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Electricity Maps /v3/zones API response breaks JSON unmarshaling

2 participants