Skip to content

Commit

Permalink
Try to implement the new CDS api
Browse files Browse the repository at this point in the history
  • Loading branch information
euskalhenriko committed Feb 3, 2025
1 parent 07a89f6 commit 5be2451
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public CopernicusCDSDatacube(String dataset, ITimeInstant dataStart, double noDa
this.dataset = dataset;
this.user = Configuration.INSTANCE.getProperties().getProperty(CDS_USER_NUMBER_PROPERTY);
this.apiKey = Configuration.INSTANCE.getProperties().getProperty(CDS_API_KEY_PROPERTY);
if (this.apiKey == null || this.user == null) {
if (this.apiKey == null) {
setOnline(false, "Copernicus CDS datacube: no CDS credentials provided in configuration");
} else {
setOnline(true, null);
Expand Down Expand Up @@ -128,16 +128,16 @@ protected boolean downloadChunk(int chunk, String variable, File destinationDire
body.put("month", this.monts[(date.getMonth() - 1) / 3]);
body.put("day", this.days);
body.put("version", CDS_API_VERSION);
body.put("format", CDS_API_FORMAT);
body.put("download_format", CDS_API_FORMAT);

configureRequest(variable, body);

String jsonBody = JsonUtils.printAsJson(body);

Logging.INSTANCE.info("requesting chunk " + chunk + " of " + variable + " to CDS API: " + jsonBody);

HttpResponse<JsonNode> response = Unirest.post(getEndpointUrl("resources/datasets/" + this.dataset))
.basicAuth(user, apiKey).header("Accept", "application/json").body(jsonBody).asJson();
HttpResponse<JsonNode> response = Unirest.post(getEndpointUrl("/datasets/" + this.dataset))
.header("PRIVATE-TOKEN", apiKey).header("Accept", "application/json").body(jsonBody).asJson();

if (response.isSuccess()) {

Expand Down Expand Up @@ -221,7 +221,7 @@ protected boolean downloadChunk(int chunk, String variable, File destinationDire
}

public String getEndpointUrl(String request) {
return "https://cds.climate.copernicus.eu/api/v2/" + request;
return "https://cds.climate.copernicus.eu/api/" + request;
}

@Override
Expand Down

0 comments on commit 5be2451

Please sign in to comment.