0

I have following code to create a task in asana .

String data = "{" + "    \"data\": {"
        + "\"workspace\":4661999437107,"
        + "\"name\": \"crmit solutions\","
        + "\"notes\": \"NOTES_ABOUT_TASK_GO_HERE\","
        + "\"assignee\": \"ravi.khare@crmit.com\"" + "}"
        // + "    \"options\": {" + "        \"fields\": \"name\"}" 
                + "}";

        HttpClient client = new HttpClient();
        client.getParams().setAuthenticationPreemptive(true);
        client.getParams().setParameter("http.useragent", "Test Client");
        client.getState().setCredentials(
                new AuthScope("app.asana.com", 443, "realm"),
                new UsernamePasswordCredentials(
                        "1k3qqT7O.RVRyxHdHRLiYSH710c6NpVl", ""));

        BufferedReader br = null;
        PostMethod method = new PostMethod(
                "https://app.asana.com/api/1.0/tasks");
        method.setDoAuthentication(true);

        try {
            method.setRequestBody(data);
            int returnCode = client.executeMethod(method);
            System.out.println("Return code: " + returnCode);
            br = new BufferedReader(new InputStreamReader(
                    method.getResponseBodyAsStream()));
            String readLine;
            while (((readLine = br.readLine()) != null)) {
                System.out.println(readLine);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            method.releaseConnection();
            if (br != null)
                try {
                    br.close();
                } catch (Exception fe) {
                    System.err.println(fe);
                }
        }

but it is giving me an Error saying Return code: 400 {"errors":[{"message":"workspace: Not the correct type"}]}

Please Help !!

Ravi
  • 19
  • 1

2 Answers2

0

It means that the value passed for workspace is of incorrect type. Cross check the type of value it accepts.

If its string, your request json needs to have double-quotes("") around the value for workspace.

If its an array, then your request needs to be framed accordingly(square braces[] around the list of values).

Just make sure that the type of value is in sync.

Rahul
  • 44,383
  • 11
  • 84
  • 103
  • Your advice is good, though in this case it won't actually solve his problem. We should improve the error message to make it more clear that it's the object being referred to that is of the wrong type, not the JSON value. :) – Greg S Mar 26 '13 at 16:43
0

(I work at Asana.)

This error message means the ID you passed in, 4661999437107, refers to an object that is not a workspace. Use the /workspaces endpoint to get a list of the workspaces you are in.

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