yassirh / digitalocean-swimmer

This is a nonofficial application for the users of DigitalOcean who wish to manage their droplets, snapshots, images and domains via an android application. That communicates with DigitalOcean’s API.
MIT License
226 stars 58 forks source link

Error: The provided ssh_keys value must be an array. #58

Open rolandstarke opened 8 years ago

rolandstarke commented 8 years ago

Hi,

I want to create a droplet with ssh keys but when I try to, I get the following error: "The provided ssh_keys value must be an array."

The request is

{
    "region": "fra1",
    "ipv6": false,
    "private_networking": false,
    "ssh_keys": "[1767243]",
    "name": "test",
    "image": 15943679,
    "backkups": false,
    "size": "512mb"
}

ssh_keys should be like [1767243] or ["1767243"]

On Android 4.2.2, DO Swimmer 2.2.1

Roland

rolandstarke commented 8 years ago

maby this is an issue with some with older android versions. looks like your List<String> gets stringifyed when you pass it as argument to options.put

maby if you change to following lines

List<String> keys = new ArrayList<>();
for (Long key: selectedSSHKeysIds) {
    keys.add(key.toString());
}
options.put("ssh_keys", keys);

to

JSONArray keys = new JSONArray();
for (Long key: selectedSSHKeysIds) {
    keys.put(key.toString());
}
options.put("ssh_keys", keys);

it solves this issue.

DISCLAIMER: I don't know Java.