Java - API - create Instance - "This field is required"

99 views
Skip to first unread message

critak

unread,
Jun 20, 2011, 8:22:53 AM6/20/11
to SpotCloud Buyers
Hi !

thought it would be nice to open another thread for this theme.
Maybe it helps other :)

Ok, i can't create a instance! ... this is my code:

################################################

HashMap creaIn = new HashMap();
creaIn.put("hardware",
"aglzcG90Y2xvdWRyEAsSCEhhcmR3YXJlGIqDDAyiAQMxLjI");
creaIn.put("appliance",
"aglzcG90Y2xvdWRyDwsSB1BhY2thZ2UY0t8CDKIBAzEuMg");


System.out.println("Creat Instance:");
System.out.println(post(accessToken,"/api/v1/buyer/instances/
list", creaIn, "xml"));


################################################

My post method is simular to the get method:


################################################

public static String post(Token token, String path, HashMap
params, String respType) {
String paramString = "";

if(params != null) {
Set set = params.entrySet();
Iterator it = set.iterator();
while(it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
paramString += "&" + entry.getKey() + "=" +
entry.getValue();
}
paramString = paramString.substring(1);
}

OAuthRequest request = new OAuthRequest(Verb.POST,
host + path + "." + respType + "?" + paramString);

request.getUrl();
System.out.println("HIER: "+request.getUrl());

service.signRequest(token, request);
Response response = request.send();
return response.getBody();
}


################################################

i still receive :

<object>
<hardware>This field is required</hardware>
<appliance>This field is required</hardware>
</object>

critak

unread,
Jun 23, 2011, 4:10:27 AM6/23/11
to spotclo...@googlegroups.com
any ideas ?

adam boduch

unread,
Jun 24, 2011, 9:42:38 AM6/24/11
to spotclo...@googlegroups.com
Hi,

I'm not a Java guy, but from what I could make of your code, everything looks good.  You're posting to the correct resource, using the right parameters, etc.

My only thoughts are that the HTTP POST payload isn't getting through to the API for some reason, which would explain why the API processes your request, but doesn't find anything in the POST message.

Maybe there is a way you can dump the full HTTP message being sent.  If so, you could potentially try running the Python API example to compare the two.

Regards,

Adam

On Thu, Jun 23, 2011 at 4:10 AM, critak <robinh...@gmail.com> wrote:
any ideas ?

critak

unread,
Jun 28, 2011, 4:28:52 AM6/28/11
to spotclo...@googlegroups.com
Ok ! Deadend ;)

Could somebody post Working java code for creating instances ?

critak

unread,
Jul 5, 2011, 11:10:38 AM7/5/11
to spotclo...@googlegroups.com
Help yourself:
;-)

Hope this will help others.
@ SpotCloud: Update your API Documentation.


    public static String post(Token token, String path, HashMap params) {
           
        OAuthRequest request = new OAuthRequest(Verb.POST, host + path + ".xml");

       
        if(params != null) {
            Set set = params.entrySet();
            Iterator it = set.iterator();
            while(it.hasNext()) {
                Map.Entry entry = (Map.Entry)it.next();
                request.addBodyParameter((String)entry.getKey(), (String)entry.getValue());

               
            }
        }
        service.signRequest(token, request);
        Response response = request.send();
        return response.getBody();       
    }

Best regards
Robin
Reply all
Reply to author
Forward
0 new messages