SystemLink Forum

cancel
Showing results for 
Search instead for 
Did you mean: 

Help querying files from SystemLink using SystemLink python API FileIngestionClient

Solved!
Go to solution

I want to query all files stored in my SystemLink server using python. I am using the FileIngestionClient API from the python SDK. 

 

I currently am able to pull some of the files stored, so my connection to the server is working correctly. My issue is that I want files from Workspaces but right now I can only grab files stored in Default. 

 

How do I go about changing my query so that I can pull from other Workspaces on the server?

 

Thanks in advance.

0 Kudos
Message 1 of 6
(1,837 Views)

I believe I have found the issue to this problem. 

 

The FileIngestionClient API uses AMQP to connect to the server. According to SystemLink's RBAC documentation, the workspace is always 'Default' on this type of connection.

 

Thank you all for your continued support.

Message 2 of 6
(1,825 Views)
Solution
Accepted by craneMac

Here is an example that uses the newer HTTP Python client.

 

https://github.com/ni/systemlink-server-examples/blob/master/jupyter/FileServiceExample.ipynb

Message 3 of 6
(1,795 Views)

Thanks for this, its what I was looking for. 

0 Kudos
Message 4 of 6
(1,771 Views)

I have been having trouble getting this to work properly. The example provided seems to only work for a locally hosted server. 

 

For the FileIngestionClient Api, I got around this issue by creating an AmqpConfiguration object and passing in the skyline configuration file's variables that linked to the remote server, then using the AmqpConfiguration as a parameter in a FileIngestionClient object. Doing this, I was able to query, delete, replace etc all the files on the server that were in the Default workspace. 

 

I tried to do this same method with the nifile API and am having trouble getting responses from the server. For the configuration file, I am using the username, password, and host from the skyline configuration file, and the api key from the http configuration file.

I then create an ApiClient object with that configuration as a parameter,

then a filesApi object with the ApiClient as a parameter.

 

When I try to follow the rest of the example and use the following code:

res = await fileApi.query_available_files(query=query)
print(res)

 

I recieve the error:

res = await fileApi.query_available_files(query=query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'await' outside function

 

If you fine people have any ideas that would be most appreciated.

0 Kudos
Message 5 of 6
(1,757 Views)

I think your approach is generally correct.  It looks like the error you're getting is unrelated to the configuration you're building up.

 

Here is an example that may do what you need:

 

from systemlink.clientconfig.configuration import Configuration
from systemlink.clients.nifile.api_client import ApiClient
from systemlink.clients.nifile.api.files_api import FilesApi
from systemlink.clients.nifile.models.query_available_files_request import QueryAvailableFilesRequest
from systemlink.clients.nifile.models.property_query import PropertyQuery

config_dict = {
    'Uri': 'https://<YOUR HOSTNAME HERE>/'
}
config = Configuration(config_dict, '/nifile', '')

config.api_key='<YOUR API KEY HERE>'

 

api_client = ApiClient(config)
files_api = FilesApi(api_client)

 

file_name = 'test.txt'
property_query = PropertyQuery(key="Name", operation="EQUAL", value=file_name)
query = QueryAvailableFilesRequest(properties_query=[property_query])

res = await files_api.query_available_files(query=query)
print(res)

Message 6 of 6
(1,742 Views)