08-05-2022 03:25 PM
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.
Solved! Go to Solution.
08-05-2022 05:04 PM
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.
08-06-2022 12:56 PM
Here is an example that uses the newer HTTP Python client.
https://github.com/ni/systemlink-server-examples/blob/master/jupyter/FileServiceExample.ipynb
08-09-2022 10:36 AM
Thanks for this, its what I was looking for.
08-10-2022 04:38 PM
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.
08-12-2022 11:42 AM
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)