Create Project through Python API

LabKey Support Forum
Create Project through Python API David Owen  2019-09-12 07:51
Status: Closed
 

Is it possible to dynamically create a project through the Python API? I couldn't find much information in the documentation. If not, are there any other tools I can use to programmatically create projects?

Thanks,
Dave

 
 
Jon (LabKey DevOps) responded:  2019-09-26 12:44
Hi Dave,

Unfortunately, the Python API has not been wired to create new containers.

At the moment, the only documented APIs that have the means to create new containers are the Javascript API and the Java API:

https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.Security.html#.createContainer
https://www.labkey.org/download/clientapi_docs/java-api/org/labkey/remoteapi/security/CreateContainerCommand.html

Regards,

Jon
 
David Owen responded:  2019-10-09 02:03
Status: Active
Hi Jon,

I've had a go using the Java Client API, but I can't seem to connect to the server, even though it connects via the Python API.

Python Code:
#!/usr/bin/env python3
import labkey
from labkey.utils import create_server_context
from labkey.query import select_rows

labkey_server = 'PUBLIC_IP'
project_name = 'home'
schema = 'core'
table = 'Users'

server_context = create_server_context(labkey_server, project_name, use_ssl=False)

result = select_rows(server_context, schema, table)

try:
    print(result['rows'][0])
    print("select_rows: Number of rows returned: " + str(result['rowCount']))
except IndexError:
    print('select_rows: Failed to load results from ' + schema + '.' + table)


Java:
import java.util.*;
import org.labkey.remoteapi.*;
import org.labkey.remoteapi.query.*;

public class connectionTest{
    public static void main(String[] args){
        String user = "ADMIN_EMAIL";
        String password = "ADMIN_PASSWORD";
        Connection cn = new Connection("PUBLIC_IP", user, password);

        SelectRowsCommand cmd = new SelectRowsCommand("core", "Users");
        SelectRowsResponse response = cmd.execute(cn, null);
    }
}
ERROR:
connectionTest.java:12: error: unreported exception IOException; must be caught or declared to be thrown
        SelectRowsResponse response = cmd.execute(cn, null);
 
Jon (LabKey DevOps) responded:  2019-10-25 23:06
Status: Closed
Hi David,

Our Community Forum Guidelines (https://www.labkey.org/home/Support/wiki-page.view?name=communityForumGuidelines) are limited to basic LabKey Server topics. Debugging code is something available with our Premium Editions of LabKey. If you are interested in our Premium Editions of LabKey, please feel free to submit a request through our contact form here: https://www.labkey.com/about/contact

In the meantime, I would recommend looking at our code samples here:

https://svn.mgt.labkey.host/stedi/trunk/remoteapi/java/src/org/labkey/remoteapi/test/Demo.java
https://svn.mgt.labkey.host/stedi/trunk/remoteapi/java/src/org/labkey/remoteapi/Connection.java

Regards,

Jon
 
Jon (LabKey DevOps) responded:  2019-10-25 23:13
Also, you can get a good set of Java code via the Export function on a grid, including the grid for the Site Users grid, which is what core.Users is tied to:

https://www.labkey.org/Documentation/wiki-page.view?name=exportScripts

That Java code shows a connection string with the selectRows function.