Announcement

Collapse
No announcement yet.

OX HTTP API create folder

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • OX HTTP API create folder

    Hello!

    I will create a contact folder with the http api.

    The JSONObejct, which i send to the server will look like this:

    Code:
    {"data":[{"folder_id":"57","title":"kontakte","module":"contacts","type":"1"}]}
    But i get this error:

    Code:
    {"category":7,"error":"A JSONObject text must begin with '{' at character 0 of ","error_id":"766414115-12968","data":null,"code":"FLD-9999"}
    I don't know, but I tried something and a I read also the http-api, but i can't find the error. I also tried without the data field and without the JSONArray, but it didn't work.

    My be, someone can help me!

    Best regards!

  • #2
    Hi,

    a usual PUT content for creating a folder looks like this:
    Code:
    http://ox-server.tld/ajax/folders?action=new&folder_id=26&session=c67a692db1374bfeafc37e6011304d60
    
    {"title":"mytitle","module":"contacts","permissions":[{"group":false,"bits":403710016,"entity":3}],"subscribed":1}
    folder_id:26 is the id of the root folder where the new folder is going to be created.

    Greetings

    Comment


    • #3
      Hi,

      i did't work!

      My JSONObject look like this:
      Code:
      {"title":"kontakte","module":"contacts","permission":[{"group":"false","bits":"403710016","entity":"3"}],"subscribed":"1"}
      And I use the Put command to upload to the server, but i get always this response:

      Code:
      {"category":7,"error":"A JSONObject text must begin with '{' at character 0 of ","error_id":"766414115-13566","data":null,"code":"FLD-9999"}
      I don't know what i should do!

      Update:
      This code is responsible for the upload:
      Code:
      RequestEntity data = new StringRequestEntity(jsonObject.toString(), CONTENT_TYPE_JSCRIPT, CHARSET_JSCRIPT);
      
      createMethod.setRequestEntity(data);
      client.executeMethod(createMethod);
      String tmp = createMethod.getResponseBodyAsString();
      JSONObject jsonObjectResponse = JSONObject.fromObject( tmp );  
      logger.info(jsonObjectResponse);
      Last edited by cvallant; 01-20-2010, 07:36 PM.

      Comment


      • #4
        Could you provide the entire HTTP conversation, not just the body?

        Comment


        • #5
          Hello,

          sorry for the long delay! Now the responsible code:

          Create the JSONObject:
          Code:
          JSONObject jsonObject = new JSONObject();
          jsonObject.put("title", subject.elementAt(0));
          jsonObject.put("module", "contacts");
          
          JSONArray jsonArray = new JSONArray();
          JSONObject jsonObject1 = new JSONObject();
          jsonObject1.put("group", "false");
          jsonObject1.put("bits", "403710016");
          jsonObject1.put("bits", "403710016");
          jsonObject1.put("entity", "3");
          jsonArray.add(jsonObject1);
          
          jsonObject.put("permission", jsonArray);
          jsonObject.put("subscribed", "1");
          
          logger.info(jsonObject);
          
          
          http.createOXFolder(session, parentid, jsonObject);
          And now the code, which sends the JSONObject to the server:
          Code:
          public Vector<JSONArray> createOXFolder(String session, String folder_id, JSONObject jsonObject) {
          
          		PutMethod createMethod = new PutMethod("http://"+oxserver+"/ajax/folders");
          
          		NameValuePair[] pairs = { 
          				new	NameValuePair("action", "new"), 
          				new NameValuePair("folder_id", folder_id),
          				new NameValuePair("session", session)
          		};
          
          		createMethod.setQueryString(pairs);
          
          		try {
          
          
          				logger.info("jsonObject:##"+jsonObject.toString()+"##");
          
          				RequestEntity data = new StringRequestEntity(jsonObject.toString(), CONTENT_TYPE_JSCRIPT, CHARSET_JSCRIPT);
          
          				createMethod.setRequestEntity(data);
          
          				client.executeMethod(createMethod);
          
          				String tmp = createMethod.getResponseBodyAsString();
          
          				JSONObject jsonObjectResponse = JSONObject.fromObject( tmp );  
          				logger.info(jsonObjectResponse);
          
          				/*
          				if(jsonObjectResponse.containsKey("error")){	
          
          					logger.info((jsonObjectResponse.get("error").toString()).replace("%s", jsonObjectResponse.get("error_params").toString())) ;		
          
          				}
          				 */
          		}
          		catch (Exception e) {
          			logger.error(e);
          		}
          
          		return null;
          	}
          I don't know, what the problem is. I got this error:

          Code:
          {"category":7,"error":"Expected a ':' after a key at character 143 of {{\"title\":\"kontakte\",\"module\":\"contacts\",\"permission\":[{\"group\":\"false\",\"bits\":\"403710016\",\"entity\":\"3\"}],\"subscribed\":\"1\",\"capabilities\":\"3\"}}","error_id":"766414115-30077","data":null,"code":"FLD-9999"}
          Last edited by boutl1981; 01-28-2010, 03:56 PM.

          Comment


          • #6
            I asked for data, not code.

            What bytes are sent between the server and the client? Use a sniffer like Wireshark or "tcpdump -s 0 -w dump.pcap port 80" to save a complete dump of HTTP traffic (don't use HTTPS, and use a temporary password).
            Last edited by Viktor Pracht; 01-29-2010, 12:22 PM.

            Comment

            Working...
            X