Menu

How to get the API Working?

2016-03-27
2016-12-31
  • Jason Ching

    Jason Ching - 2016-03-27

    Hi,

    I am new to PHP and Apache. I have been trying to understand the code and how the framework works, but just can't figure it out how to make the API call yet.

    What I want to do is to use Java or .NET to do the API operation becuase those are the main languages of our team.

    I have set alias 'seeddms' in Apache for the root of the application, so a home page visit is
    http://localhost/seeddms

    What is the URL of the REST API? I have tried the following, but all return a 404 error. I am trying these based on the routing statements in restapi\index.php.
    http://localhost/seeddms/document/1
    http://localhost/seeddms/restapi/document/1

    $app->get('/document/:id', 'getDocument');
    $app->delete('/document/:id', 'deleteDocument');
    $app->post('/document/:id/move', 'moveDocument');
    $app->get('/document/:id/content', 'getDocumentContent');
    $app->get('/document/:id/versions', 'getDocumentVersions');
    $app->get('/document/:id/version/:version', 'getDocumentVersion');
    $app->get('/document/:id/files', 'getDocumentFiles');
    $app->get('/document/:id/file/:fileid', 'getDocumentFile');
    

    This is my Apache setting:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        <Directory />
            Require all granted
        </Directory>
    
        Alias /seeddms “/home/www-data/seeddms43x/www/"
        <Directory "/home/www-data/seeddms43x/www/">
            DirectoryIndex index.php
            AllowOverride All
            Order deny,allow
            Deny from all
            Allow from all
        </Directory>
    </VirtualHost>
    
     
    • Stefan Kilger

      Stefan Kilger - 2016-04-06

      In .NET using RestSharp you can make the API call with the following code

      var client = new RestClient(@"http://localhost/seeddms/restapi/index.php"); 
      client.CookieContainer = new System.Net.CookieContainer(); // Cookie Managment für Login
      
      //Maybe you must Login before some API calls, use same client object, for cookie managment
      
      var request = new RestRequest(string.Format("/document/{0}", document_id), RestSharp.Method.GET); 
      request.AddHeader("Accept", "application/json"); 
      // execute the request
      IRestResponse response = client.Execute(request);
      var content = response.Content; // raw content as string
      
       
  • Manikandarajan

    Manikandarajan - 2016-12-27

    Is there any sample code for JAVA or any documentation available ?

     
  • Manikandarajan

    Manikandarajan - 2016-12-27

    i've tried to open http://localhost:8080/seeddms/restapi/login from the browser - its showing the text box for entering username and password after entering the username and password it returns {"success":true,"message":"","data":"1"} . I dont know how to proceed further with other API calls. can anybody explain how to call the create folder method - im trying to open a specfic folder in seeddms from my java application. please help

     
  • Manikandarajan

    Manikandarajan - 2016-12-29

    How to get cookie information when calling login REST call and pass it to call other REST url ? I'm trying from JAVA application. while calling the Login rest service - its returing the json value. I dont know how to pass that info for calling other REST service

     

    Last edit: Manikandarajan 2016-12-29
  • Manikandarajan

    Manikandarajan - 2016-12-29

    Hi, In java i've preserved the login cookie and send that along with the other REST call - it works fine

    String COOKIES_HEADER = "Set-Cookie";
         final java.net.CookieManager msCookieManager = new java.net.CookieManager();
         Map<String, List<String>> headerFields = con.getHeaderFields();
            List<String> cookiesHeader = headerFields.get(COOKIES_HEADER);
            if (cookiesHeader != null) {
                for (String cookie : cookiesHeader) {
                    msCookieManager.getCookieStore().add(null,HttpCookie.parse(cookie).get(0));
                }               
            }
    
            sendGet(msCookieManager);
    
     
  • Manikandarajan

    Manikandarajan - 2016-12-29

    I'm trying to redirect my java application to seeddms dashboard after some REST calls. while opening the seeddms dashboard it shows login screen, is there any way can we bypass the user login to open seeddms dashboard in the browser.

     
    • Phaser Fill

      Phaser Fill - 2016-12-29

      Try to make get request in your browser. It works for me on 5.0.8 version
      http://[server]:[port]/op/op.Login.php?login=User1&pwd=Pass1234&referuri=/out/out.AdminTools.php
      (referuri parameter is optional).

       
  • Manikandarajan

    Manikandarajan - 2016-12-30

    Thanks for the reply, I've tried with my 4.3.13 and its not working, let me change the version and update the status.

     
  • Manikandarajan

    Manikandarajan - 2016-12-30

    Can anyone share the url pattern for create folder REST api call, I've tried
    http://[server]:[port]/seeddms/restapi/index.php/folder/[foldername]/createfolder
    but it returns success without folder id and the folder is not created.

     
    • Phaser Fill

      Phaser Fill - 2016-12-30

      You should send folderID instead foldername

      POST http://[server]:[port]/restapi/index.php/folder/[id of parent folder]/createfolder HTTP/1.1
      Accept-Encoding: gzip,deflate
      Content-Type: application/x-www-form-urlencoded
      Cookie: mydms_session=[your session id]
      Content-Length: 16
      Host: [server]:[port]
      Connection: Keep-Alive
      User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

      name=[name of new folder]

       

      Last edit: Phaser Fill 2016-12-30
  • Manikandarajan

    Manikandarajan - 2016-12-30

    Hi Phaser Fill, VERY MUCH THANKS for your hint. i've tried with your settings. but getting 500 response code. please find below code and advice me where i've made the mistake. if i give the folder id which is not available instead of 4 anyother value - im getting {"success":false,"message":"","data":""} .. but i'm trying to create folder under the folderid 4.

    apache log: 10.44.13.152 - - [30/Dec/2016:15:23:17 +0530] "POST /seeddms/restapi/index.php/folder/4/createfolder HTTP/1.1" 500 1486

    String url = "http://10.44.13.152:8080/seeddms/restapi/index.php/folder/4/createfolder";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

                // add request header
                con.setRequestMethod("POST");
    
                con.setRequestProperty("Accept-Encoding", "gzip,deflate");
                con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                con.setRequestProperty("Cookie", StringUtils.join(msCookieManager
                        .getCookieStore().getCookies(), ";"));
                con.setRequestProperty("Content-Length","16");
                con.setRequestProperty("Host","http://10.44.13.152:8080");
                con.setRequestProperty("Connection","Keep-Alive");
                con.setRequestProperty("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)");
    
    
                System.out.println("executing createfolder method");
    
                String urlParameters = "name=testfolder";
    
    
                con.setDoOutput(true);
                DataOutputStream wr = new DataOutputStream(con.getOutputStream());
                wr.writeBytes(urlParameters);
    
                wr.flush();
                wr.close();
    
                int responseCode = con.getResponseCode();
                System.out.println(responseCode);
    
                if (responseCode != 200) {
                    throw new RuntimeException("Failed : HTTP error code : "
    
                            + con.getResponseCode());
                }
    
                BufferedReader br = new BufferedReader(new InputStreamReader(
                        (con.getInputStream())));
    
                String output;
    
                System.out.println("Output of create folder \n");
                while ((output = br.readLine()) != null) {
                    System.out.println(output);
    
    
                }
    
     

    Last edit: Manikandarajan 2016-12-30
    • Phaser Fill

      Phaser Fill - 2016-12-30

      Hi!

      1. Sorry, I'm not good in Java :) I've attached SOAPUI project that contains some successful requests to SeedDMS. Please see it
      2. Try to send request without this lines:

      con.setRequestProperty("Accept-Encoding", "gzip,deflate");
      con.setRequestProperty("Content-Length","16");
      con.setRequestProperty("Host","http://10.44.13.152:8080");
      con.setRequestProperty("Connection","Keep-Alive");
      con.setRequestProperty("User-Agent", "Apache-HttpClient/4.1.1 (java 1.5)");

       
  • Manikandarajan

    Manikandarajan - 2016-12-31

    Thank you very much Phaser Fill , I'm trying with different combinations of setRequestProperty and share the info if it started working.

     

Log in to post a comment.

MongoDB Logo MongoDB