0

I was wondering if you've had any success performing a PUT request on one of your exposed api methods (update workspace in this case) using Java EE.

I currently have the following snippet but am getting a 400. For the data variable, I have tried probably every single permutation of where to place double quotes, what to encode, and also have tried JSON.

String data = URLEncoder.encode("name=My Sandbox", "UTF-8")
URL url = new URL("https://app.asana.com/api/1.0/workspaces/7**********2");
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setRequestMethod("PUT");
String login = "dm**********************v8:";
String encodedLogin = new BASE64Encoder().encode(login.getBytes());
conn.setRequestProperty("Authorization", "Basic " + encodedLogin);
OutputStreamWriter wr = null;
conn.setDoOutput(true);
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {
    sb.append(line);
}
wr.close();
rd.close();
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140

1 Answers1

0

The operation you're attempting (using PUT to update a workspace name) should work. I believe your problem is that you are URLEncoding the entire string "name=My Sandbox" and not the key and value independently. So I suspect that the data payload you're sending is:

name%3DMy%20Sandbox

Whereas it should be:

name=My%20 Sandbox

When the API servers errors they often including some kind of diagnostic message which should help you uncover the problem. If the above fix doesn't work, can you provide the error message you're receiving?

Greg S
  • 2,079
  • 1
  • 11
  • 10