[Developers] Java and mql write service

Ben Drees ben at metaweb.com
Tue Feb 19 18:29:34 UTC 2008


Hi Christian,

The HTTP error response bodies usually provide clues as to what's going on.

It looks like you're getting back response bodies that include the message
"one of query=, or queries= must be provided", which points to a missing 
"queries="
prefix in your 'envelope' variable.

-Ben

Dae Park wrote:
> Do you have the message detail (JSON response) of the 400 response  
> you are getting?
>
> Make sure you are doing a POST and your post parameter looks like:
>
> queries={'qname':{'query':{...}}}
>
> -dae
>
> On Feb 18, 2008, at 7:07 PM, Christian Hirsch wrote:
>
>   
>> Hi All,
>>
>> I am trying to access the write API using Java, but somehow I  
>> always get an error.
>> Sending read and login requests works just fine, however when I'm  
>> sending write requests I'm always getting '400 bad request'. I'm  
>> not very familiar with http requests in java... could there be  
>> something wrong with the request header? or the credentials? -  
>> maybe someone has some working example code?
>>
>> this is the code I'm using:
>>
>> query = "{\"create\":\"unless_exists\",\"id\":null,\"type\":\"/ 
>> common/topic\", \"name\":\"test_xy\"}";
>> String envelope = "{\"qname\":{\"query\":" +query+ "}}";
>> String data = URLEncoder.encode(envelope, "UTF-8");
>>
>> URL url = new URL("http://sandbox.freebase.com/api/service/mqlwrite");
>> URLConnection conn = url.openConnection();
>> conn.setDoInput(true);
>> conn.setDoOutput(true);
>>
>> String credentials = "metaweb-user=..."; // value of the Set-Cookie  
>> from the login response
>> conn.setRequestProperty("Cookie", credentials);
>> conn.setRequestProperty("X-Metaweb-Request", "True");
>> conn.setRequestProperty("Content-type", "application/x-www-form- 
>> urlencoded");
>>
>> OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream 
>> ());
>> wr.write(data);
>> wr.flush();
>>
>> BufferedReader rd = new BufferedReader(new InputStreamReader 
>> (conn.getInputStream()));
>> //write the response to a JSON object...
>> wr.close();
>> rd.close();
>>
>>
>> Thanks,
>> Christian
>> _______________________________________________
>> Developers mailing list
>> Developers at freebase.com
>> http://lists.freebase.com/mailman/listinfo/developers
>>     
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
>
>   



More information about the Developers mailing list