ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MS SharePoint Online

 Hi, 

 

I'm looking for some help with authenticating from LabVIEW to Microsoft SharePoint using a client_id and client_secret

 

I have a snippet of Python code that seems to do the trick, but I am looking to do this all in LabVIEW as my solution needs to be compatible back to LV2011. Initially I tired using the RESTful API but hit a dead end as it would only give me a username and password (I'm not an expert in Python).

Here is the python:

from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.client_credential import ClientCredential

site_url = '<myURL>'

app_principal = {
'client_id': '<myClientId>',
'client_secret': '<myClientSecret>',
}

credentials = ClientCredential(app_principal['client_id'], app_principal['client_secret'])

ctx = ClientContext(site_url).with_credentials(credentials)

web = ctx.web

ctx.load(web)

ctx.execute_query()

print("Web site title: {0}".format(web.properties['Title']))

 

 

Again through google search I came across a MS article doing something similar with the SharePoint Client dll. However I get stuck at the context.load(web) function as it does not appear to be part of the property node.

KevR_F1_0-1663338609704.png

 

 

Complete basic operations using SharePoint client library code | Microsoft Docs

 

 

 

Any help would be greatly appreciated, or advice with how to do this a better way through LabVIEW. Ideally I would want to use the RESTful API as this is well documented across the web with doing various tasks on Sharepoint.

 

 

Thanks

 

Kev

 

0 Kudos
Message 1 of 3
(1,853 Views)

@KevR_F1 wrote:

 Hi, 

 

I'm looking for some help with authenticating from LabVIEW to Microsoft SharePoint using a client_id and client_secret

 

I have a snippet of Python code that seems to do the trick, but I am looking to do this all in LabVIEW as my solution needs to be compatible back to LV2011. Initially I tired using the RESTful API but hit a dead end as it would only give me a username and password (I'm not an expert in Python).

Here is the python:

from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.client_credential import ClientCredential

site_url = '<myURL>'

app_principal = {
'client_id': '<myClientId>',
'client_secret': '<myClientSecret>',
}

credentials = ClientCredential(app_principal['client_id'], app_principal['client_secret'])

ctx = ClientContext(site_url).with_credentials(credentials)

web = ctx.web

ctx.load(web)

ctx.execute_query()

print("Web site title: {0}".format(web.properties['Title']))

 

 

 

If you have python that works, try using a LabVIEW python node. see this (or google it): 

https://blog.sasworkshops.com/python-node-basics/

 

Once you open a handle in python you may need to keep calling the python session to interact with it. 

 

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 2 of 3
(1,848 Views)

Hi, 

 

Thanks for your reply. I wish it was as simple as that. My code needs to be backward compatible with LV2011 which the python node is only support as far back as LV2018, unless I am misinformed (Integrating Python Code in LabVIEW). 

 

Many thanks

 

Kev

0 Kudos
Message 3 of 3
(1,786 Views)