2013-03-25 5 views
0

다음 코드는 asana에서 작업을 생성하는 데 사용됩니다.응답에 오류가 발생했습니다.

String data = "{" + " \"data\": {" 
     + "\"workspace\":4661999437107," 
     + "\"name\": \"crmit solutions\"," 
     + "\"notes\": \"NOTES_ABOUT_TASK_GO_HERE\"," 
     + "\"assignee\": \"[email protected]\"" + "}" 
     // + " \"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); 
       } 
     } 

그러나 그것은 나에게 오류 말하는 반환 코드를주고있다 : 400 { "오류": [{ "메시지": "작업 공간 : 아니 올바른 유형"}]}

제발 도와주세요!

답변

0

이는 workspace에 전달 된 값이 유형으로 잘못되었음을 의미합니다. 받아들이는 가치 유형을 교차 확인하십시오.

문자열의 경우 사용자의 json이 의 작업 영역 값 주위에 큰 따옴표 ("")을 가져야합니다.

배열의 경우 배열에 따라서 값의 테두리를 따라 (대괄호 []) 요청을 프레임해야합니다.

값 유형이 동기화되어 있는지 확인하십시오.

+0

이 경우 실제로 문제를 해결하지는 않더라도 조언은 훌륭합니다. 오류 메시지를 개선하여 JSON 값이 아닌 잘못된 유형의 참조 된 객체임을 분명히해야합니다. :) –

0

(나는 아사에서 작동합니다.)

이 오류 메시지가, 4661999437107, 당신이 전달 된 ID를 의미 작업 공간이 아닌 객체를 참조합니다. /workspaces 엔드 포인트를 사용하여 현재있는 작업 공간의 목록을 가져 오십시오.

관련 문제