Office365-REST-Python-Client Connected but no items showing - sharepoint

I'm trying to access sharepoint with Office365-Rest. I'm using the app connection process described here:
https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs
I set permissions to
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope=" https://*.sharepoint.com/sites/Engineering/content/tenant" Right="FullControl" />
</AppPermissionRequests>
Python Code:
import sys
from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.http.request_options import RequestOptions
from office365.sharepoint.client_context import ClientContext
client_id="*"
client_secret="*"
sp='https://*.sharepoint.com/sites/Engineering/'
client_credentials = ClientCredential(client_id,client_secret)
web = ctx.web.get().execute_query()
print(web.url)
ctx = ClientContext(sp).with_credentials(client_credentials)
list_source = ctx.web.lists.get_by_title("PDF")
items = mylist.get_items().select("ID").top(10)
ctx.execute_query()
for i in items:
print(i)
My connection goes through. I get the web.url printed. If I change the folder or access codes, I get errors. However whatever I seem to try and get data from lists or folders, I never get any data.
I've run out of ideas on how to test or what to do next, any help would be appreciated.
I'm trying to access 3 items, 1 folder with 5000+ item, 1 list with 5000+ items and 1 folder with a 100 items. In all cases of trying to access these, I'm not getting anything. I thought with the folder of 100 items, I should get something and then I could work on developing code to go through the big lists. I've tried the following example code from the github to no avail.
https://github.com/vgrem/Office365-REST-Python-Client/blob/55252191cb7f729f044f61542dca309249c743fc/examples/sharepoint/lists_and_items/read_large_list.py
I managed to use shareplum to update lists, but that doesn't seem to currently have a workaround for 5000+ lists so I was hoping this would do it once I get the data working.

Related

Function service_account.Credentials.from_service_account_info() not working

I'm writing an application based on GCP services and I need to access to an external project. I stored on my Firestore database the authentication file's informations of the other project I need to access to. I read this documentation and I tried to apply it but my code does not work. As the documentaion says, what I pass to the authentication method is a dictionary[str, str].
This is my code:
from googleapiclient import discovery
from google.oauth2 import service_account
from google.cloud import firestore
project_id = body['project_id']
user = body['user']
snap_id = body['snapshot_id']
debuggee_id = body['debuggee_id']
db = firestore.Client()
ref = db.collection(u'users').document(user).collection(u'projects').document(project_id)
if ref.get().exists:
service_account_info = ref.get().to_dict()
else:
return None, 411
credentials = service_account.Credentials.from_service_account_info(
service_account_info,
scopes=['https://www.googleapis.com/auth/cloud-platform'])
service = discovery.build('clouddebugger', 'v2', credentials=credentials)
body is just a dictionary containing all the informations of the other project. What I can't understand is why this doesn't work and instead using the method from_service_account_file it works.
The following code will give to that method the same informations of the previous code, but inside a json file instead of a dictionary. Maybe the order of the elements is different, but I think that it doesn't matter at all.
credentials = service_account.Credentials.from_service_account_file(
[PATH_TO_PROJECT_KEY_FILE],
scopes=['https://www.googleapis.com/auth/cloud-platform'])
Can you tell me what I'm doing wrong with the method from_service_account_info?
Problem solved. When I posted the question I manually inserted from the GCP Firestore Console all the info about the other project. Then I wrote the code to make it authomatically and it worked. Honestly I don't know why it didn't worked before, the informations put inside Firestore were the same and the format as well.

How to access Clockify API through Excel Power Query

I am new to Clockify and to API usage (so I apologize if I express myself not properly). My objective is to automatically load in Excel (via Power Query) the detailed report with all time entries. I have tried the below code and it works ... but for the fact that I got just the latest 50 time entries.
This because, as I understand properly, I should use this base Endpoint: "https://api.clockify.me/api/v1" (the one I use is deprecated). Is there a way to make the below work on the correct Endpoint?
let Source = Web.Contents("https://api.clockify.me/api/reports/{your report ID}", [https://api.clockify.me/api", #"X-Api-Key"="{your API Key}"]]), jsonResponse = Json.Document(Source), workspace = jsonResponse[workspace] in workspace
Thanks in advance,

Navigating from Location to Workorder

I need to :
1. Create a single page location application
2. Display all the asset present in the selected location in a table
3. Provide a button from which user can navigate to WOTRACK to view all the workorder(s) created on selected location and its asset(s).
I am facing difficulty in the 3rd one. I have tried Launch in Context and it is working fine except am not able to pass sql query like 'location={location} and assetnum in ({asset.assetnum})'. I need to filter workorders with particular location and all its assets.
I tried to save all the assets in the location to a Non-persistant attribute and passing the values of the attribute in the Launch in context url, Its working as expected but to do so I have written a script on 'Initialize value' which is causing performance issues.
script goes like this:
from psdi.server import MXServer;
from psdi.mbo import MboConstants;
if app == "LOCATION1" :
if mbo.getString("LOCATION") is not None:
Locsite = mbo.getString("SITEID")
desc = mbo.getString("DESCRIPTION")
MaxuserSet = MXServer.getMXServer().getMboSet("MAXUSER", mbo.getUserInfo())
MaxuserSet.setWhere(" userid='"+user+"' ")
MaxuserSet.reset()
UserSite = MaxuserSet.getMbo(0).getString("DEFSITE")
if Locsite == UserSite:
AssetSet = mbo.getMboSet("ASSET")
AssetSet.setFlag(MboConstants.DISCARDABLE, True);
if not AssetSet.isEmpty():
AssetList = ""
AssetMbo = AssetSet.moveFirst()
while AssetMbo is not None:
AssetList = AssetList + str(AssetMbo.getString("ASSETNUM")) + "%2C"
AssetMbo = AssetSet.moveNext()
mbo.setValue("non-persitant",str(AssetList),11L)
and in the LIC url i have given : 'http://xx.x.x.xx/maximo/ui/?event=loadapp&value=wotrack&tabid=List&additionalevent=useqbe&additionaleventvalue=location={LOCATION}|assetnum={non-persistant}'
Is there any other feasible solution to the requirement?
Thanks in Advance
Launch In Context is better used for sending the user to an outside-of-Maximo application and passing along some data from inside-Maximo to provide context in that external app.
What you are doing sounds like a good place to use a workflow process with an Interaction node. The developer tells the Interaction node which app to take the user to and which Relationship to use to find the data the user should work with there.
Why don't you add a table control inside the table details (expanded table row) and show a list of the work orders there. From the WONUM in that table, you could have an app link to take them to WOTRACK, if they want more details about a particular work order. No customization (automation scripting) needed. No workflow needed. Nice and simple.

How can I access the current user's roles in Orchard from a view page?

I am trying to get the current user's roles in Orchard 1.9.2 from a view.
I tried this snippet of code but it always returns 0 roles:
var roles = ((ContentItem)WorkContext.CurrentUser.ContentItem).As<UserRolesPart>().Roles;
source: https://www.cloudconstruct.com/blog/retrieving-role-information-in-your-orchard-view-templates
Any ideas?
Perhaps the using statement is missing?
Try the following code:
#using Orchard.ContentManagement
#{
var roles = WorkContext.CurrentUser.As<Orchard.Roles.Models.UserRolesPart>().Roles;
}
edit 1
It seems like the user is not authenticated. The line of code posted above creates the following calls:
Orchard.Environment.WorkContextImplementation.GetState("CurrentUser")
Orchard.Environment.WorkContextImplementation.FindResolverForState("CurrentUser")
enumerating through a list of IWorkContextStateProvider, in this list there should be the following implementation: Orchard.Security.CurrentUserWorkContext
Orchard.Security.CurrentUserWorkContext.Get("CurrentUser")
IAuthenticationService.GetAuthenticatedUser() -> which returns the user when authenticated
So it seems that any of these steps returns without the user. I suggest you create a breakpoint in Orchard.Environment.WorkContextImplementation.GetState() to find out where the issue is.

ScriptError using Google Apps Script Execution API

Following these guides https://developers.google.com/apps-script/guides/rest/quickstart/target-script and https://developers.google.com/apps-script/guides/rest/quickstart/nodejs, I am trying to use the Execution API in node to return some data that are in a Google Spreadsheet.
I have set the script ID to be the Project Key of the Apps Script file. I have also verified that running the function in the Script Editor works successfully.
However, when running the script locally with node, I get this error:
The API returned an error: Error: ScriptError
I have also made sure the script is associated with the project that I use to auth with Google APIs as well.
Does anyone have any suggestion on what I can do to debug/ fix this issue? The error is so generic that I am not sure where to look.
UPDATE: I've included a copy of the code in this JSBin (the year function is the entry point)
https://jsbin.com/zanefitasi/edit?js
UPDATE 2: The error seems to be caused by the inclusion of this line
var spreadsheet = SpreadsheetApp.open(DriveApp.getFileById(docID));
It seems that I didn't request the right scopes. The nodejs example include 'https://www.googleapis.com/auth/drive', but I also needed to include 'https://www.googleapis.com/auth/spreadsheets' in the SCOPES array. It seems like the error message ScriptError is not very informative here.
In order to find what scopes you'd need, to go the Script Editor > File > Project Properties > Scopes. Remember to delete the old credentials ~/.credentials/old-credential.json so that the script will request a new one.
EDIT: With the update in information I took a closer look and saw you are returning a non-basic type. Specifically you are returning a Sheet Object.
The basic types in Apps Script are similar to the basic types in
JavaScript: strings, arrays, objects, numbers and booleans. The
Execution API can only take and return values corresponding to these
basic types -- more complex Apps Script objects (like a Document or
Sheet) cannot be passed by the API.
https://developers.google.com/apps-script/guides/rest/api
In your Account "Class"
this.report = spreadsheet.getSheetByName(data.reportSheet);
old answer:
'data.business_exp' will be null in this context. You need to load the data from somewhere. Every time a script is called a new instance of the script is created. At the end of execution chain it will be destroyed. Any data stored as global objects will be lost. You need to save that data to a permanent location such as the script/user properties, and reloaded on each script execution.
https://developers.google.com/apps-script/reference/properties/

Resources