I use the example given in the http api reference.
http://grafana.staged-by-discourse.com/api/dashboards/db HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: eyJrIjoiY2JKaXJsRzhNWklDQ0t2QmxlMDJTczJ2Mlp5WUxXSHYiLCJuIjoiU2FyYXRoIiwiaWQiOjF9
{
“dashboard”: {
“id”: null
},
“folderId”: 0,
“overwrite”: false,
“message”:“rti sample”
}
This is the final URL
I always end up getting:
{“message”:“Not found”}
I am putting this POST request via a Java code
private static void sendPOST() throws IOException {
POST_URL = "http://grafana.staged-by-discourse.com/api/dashboards/db";
POST_PARAMS = "{ \"dashboard\": { \"id\": null }, \"folderId\": 0, \"overwrite\": false, \"message\": \"rti sample\" }";
URL obj = new URL(POST_URL);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer eyJrIjoiY2JKaXJsRzhNWklDQ0t2QmxlMDJTczJ2Mlp5WUxXSHYiLCJuIjoiU2FyYXRoIiwiaWQiOjF9");
//con.setRequestProperty("User-Agent", USER_AGENT);
// For POST only - START
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.write(POST_PARAMS.getBytes());
os.flush();
os.close();
// For POST only - END
int responseCode = con.getResponseCode();
System.out.println("POST Response Code :: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) { //success
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
System.out.println(response.toString());
} else {
System.out.println("POST request not worked");
}
}
I get the following error:
POST Response Code :: 40
I tried reading up a lot, but i didnt get it to work.
Please help.