java-ovh icon indicating copy to clipboard operation
java-ovh copied to clipboard

get call with parameters doesn't work and returns 400 bad parameters

Open aragoubi opened this issue 6 years ago • 1 comments

I am trying to use a GET endpoint with parameters. this is the endpoint:

GET /telephony/{billingAccount}/line/{serviceName}/statistics

Parameters: timeframe: string;
type : string

This is how I am doing the call:

api.get("/telephony/{myBuildingAccount}/line/{myServiceNumber}/statistics", "timeframe=daily&type=maxDelay", true);

But I am getting an error 400 bad parameters.

aragoubi avatar May 16 '19 15:05 aragoubi

your server where you execute the code doesnt have good time (1 minute difference). you need to compute the good time to set in header siganture: private static final String AUTH_TIME = "/auth/time"; String endpoint="https://eu.api.ovh.com/1.0"; //tochange private long timeDelta() { try { Scanner sc = new Scanner(new URL(endpoint + AUTH_TIME).openStream()); long serverTime = sc.nextLong(); sc.close();

        long currentTime = new Timestamp(new Date().getTime()/1000).getTime();

        return currentTime - serverTime;
    } catch (Exception e) {
        throw new RuntimeException("Can't compute time drift for " + endpoint, e);
    }
}
private long getTimeSignature() {
    return new Timestamp(new Date().getTime()/1000).getTime() - timeDelta();
}

oliviermorpa avatar Dec 06 '20 07:12 oliviermorpa