Trello API returning 404 when called from Java, despite valid CURL request

Hi - I’m calling the rest api from some java code hosted on google cloud. A few weeks ago, it was running successfully, yet today I run the same code and I get a 404 from the trello api call. If I curl (or use postman) the same URL from within cloud shell it successfully returns the data.

Any ideas?


import java.lang.System.Logger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

public class tester123 {
    public static void main(String[] args){
    HttpClient client = HttpClient.newHttpClient();
       HttpRequest request = HttpRequest.newBuilder(
            .header("accept", "application/json")
          // use the client to send the request
        HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
        if( response.statusCode() == 404){
            System.out.println("ScanBoards: Failed to get data from Trello"+response.toString());
        System.out.println("ScanBoards: Got board  data from Trello"+response.toString());
        catch(Exception e){System.out.println(e);}

Are you saying when you run it manually it works, but when the google cloud platform runs it, it doesn’t? Do you have any logging implemented?

Exactly. Java code on cloud platform doesn’t work, curl from same cloud platform terminal does.

Just error logging - not giving me any useful insight at the moment, beyond the 404.

Hello @MattCheung

I can’t see in the HttpRequest.newBuilder() definition where you’ve defined the HTTP method (PUT, GET, POST or DELETE).

Without that, how does the REST API know what type of request is being sent?

I’ll check that - but I’ve since got the code working locally with no changes, I’ll remigrate to cloudshell and try again. Can close this I think

If the same code works locally but not in cloud VM / container, it’s very likely to be a network port access / configuration issue for Java.

1 Like