python MSAL patch request "The OData request is not supported" marking message as read - python-3.x

my application has Mail.Read.Write permission for MS graph API and the application has restrict policy on exchange online . The restriction is for a security group and the mailbox folder i am trying to access is a member of that security group. get and post methods are working fine only problem is with patch . I need to mark some emails as read after processing them.
r2 = requests.patch(request_url2,
data=json.dumps(request_body2),
headers={'Content-Type': 'application/json','Authorization': 'Bearer ' + result['access_token']})
pastebin_url2 = r2.text
print("The pastebin URL is:%s"%pastebin_url2)
the same API works fine from graph explorer has anyone tried using python msal and requests...any help appreciated

Looks like the message Id changes after moving message to a different folder
so i changed my code to first mark the message as Read in Inbox and then move to a another folder instead of the other way around. I tried with ImmutableId but it also changes after moving message to different folder.

Related

Microsoft Graph API - Copying SharePoint file - Item not found

I'm working with Graph API against Microsoft Teams team's SharePoint site.
I'm following the example on this page (https://learn.microsoft.com/en-us/graph/long-running-actions-overview?tabs=http) and have an issue. I'm able to query the location provided by the copy endpoint and get a "Completed" status that also provides a ResourceId. But I'm unable to use this resource id in any queries and only getting "Item not found".
Example of paths tried:
/drives/{driveId}/items/{resource-id-returned-from-monitor-url}
/groups/{groupId}/drive/items/{resource-id-returned-from-monitor-url}
The {driveID} is the driveId specified in the parentReference.DriveId in the copy file body.
I'm using the v1 Graph endpoint to get the file.
Btw, I can see the file fine in the correct folder within SharePoint.
Any ideas?
Regards,
Oskar
I wasn't using the DriveId supplied by the /education/***/setUpResourcesFolder Location header but rather the Drive of the class.
Fixed by using the driveId part of the Location URL.

I'm getting this Docusign Error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

One of my colleagues have originally posted this question at Salesforce StackExchange but we were also advised to post it here since there might be more devs familiar here on DocuSign.
We're creating a Salesforce app that sends a PDF file to DocuSign for signing. However, when DocuSign returns the PDF, it gives us an error.
We've configured the DocuSign sandbox to return the document back to Salesforce using the information in this link: https://support.docusign.com/articles/DocuSign-for-Salesforce-Adding-Completed-Documents-to-the-Notes-and-Attachments-New
Here is the error we get in the Docusign logs when it tries to return the document back to Salesforce:
SFIntegration unable to add attachment to SF ID: 8001X000000TvWdQAK,
SF Table: Contract, Error: Unable for insert (ShareType=I)
ContentDocumentLink for Test_Completed.Error:ErrorCode =
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, fields = .Unable to insert
(ShareType=V) ContentDocumentLink for Test_Completed.Error:ErrorCode =
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, fields =
Can anyone help us what is the error all about? Thanks.
I had the similar issue. I changed the version to 39 using 'Reconfigure Login' link for the connection and it worked !
Do you have a salesforce trigger? it's probably failing and then trying to roll back the changes.
Also, check if you have "Use Content Files" checked and what version of the API you're using. If you are using V2.1 with this checkbox - you may be getting this error.
(Later Edit):
You Must install Connect for Salesforce with 39 selected. If you had 21 selected and later change to 39 - that won't work, must have it from the beginning.

Microsoft Flow - Block uploading Video files to a Sharepoint site

I am an owner of a Sharepoint site and want to make sure all members of the site don't upload video files. Since SP doesn't have the ability to filter out files by Type - I want to use Microsoft Flow to do this task.
So I have created this flow which triggers on creation of new file in Documents folder of my SP site. Then it runs a Condition, which checkes the property of "File content type" - if it starts with "video/" - then it should delete the file uploaded. It looks like this:
#startsWith(triggerOutputs()['headers']['Content-Type'], 'video/')
But when I run this Flow, I then get this error:
BadRequest. The request failed. Error code: 'InvalidRequestContent'. Error Message: 'The request content was invalid and could not be deserialized: 'Unexpected character encountered while parsing value: {. Path 'details', line 1, position 455.'.'.
What am I doing wrong?
Unfortunately there is no OOTB way to configure these settings yet. Your workaround to create a flow is just what I would have suggested. Ofcourse you can also still create a workflow that does that but why old fashioned if you already made your experience with flow.
This is a known issue and I would encourage you to vote for that feature here.
In OneDrive you can restrict certain file types from syncing using the poweshell:
Set-SPOTenantSyncClientRestriction -ExcludedFileExtensions "wmf;mp4;mkv"
For your flow I would suggest to make an extra step "get file content" and use the content type you get there for your filter instead of the one from your "triggerOutputs"

How to access a shared folder using python imaplib?

How do you access a shared folder ? This is a shared folder which is visible to other users too. I am currently using outlook where the shared folder is visible along with my personal emails
Following back on my question. After reading enough this seems to work.
While using imaplib and connecting to exchange in python 3
use this,
result, data=mail.login('personal#domain.com\shared#domain.com','personalPassword')
If you have access to this shared mailbox in outlook then you will be able to connect using this. Print the result if it says 'OK' then the code did work.
I believe this is an answer.
Posting a link here for those who are working on similar problem with a python solution.
https://medium.com/#theamazingexposure/accessing-shared-mailbox-using-exchangelib-python-f020e71a96ab
Here is the snippet:
from exchangelib import Credentials, Account
credentials = Credentials('Firstname.Lastname#someenterprise.com', 'Your_Password_Here')
account = Account('**shared_mail_box_name#someenterprise.com**', credentials=credentials, autodiscover=True)
for item in account.inbox.all().order_by('-datetime_received')[:100]:
print(item.subject, item.sender, item.datetime_received)

Opening a google drive file using the google drive api while I'm NOT signed in to google drive

This has really been bugging me for some time so any help to confirm or affirm this is much appreciated! This is also the first time I actually post a question despite being developing for a long time :)
So I have a nodejs app integrating with the Google Drive API and I want users to authorize multiple Google Drive accounts and be able to view and open (and in general just interact with) all files from the accounts that they add.
I authorize my app using the highest available scope: https://www.googleapis.com/auth/drive and because I don't want users to have to sign-in again when the access_token runs out so I also include the approval_prompt: "force" and ``access_type: "offline"` when I request my access tokens.
Everything is fine - I authorize nicely, I can delete files, I can open them, I can share them, I can download them. Except for one thing:
If I e.g. authorize horse#gmail.com and then beaver#gmail.com. Then I can still delete, share, download and preview files from both accounts. But I simply cannot open documents from horse#gmail.com in google docs for editing (because beaver#gmail.com is signed in on my local machine). The best I can do is getting to a point where it shows me the document, with the right account logged in in the top right corner of the screen, but asks me to sign-in with a button. When I click the button it just refreshes and give me the same message and the same screen.
What I've tried is:
Simply redirecting the user to the file resources alternateLink from the API
Taking the alternateLink and appending my access_token to it and then redirect the user to it.
(and a ton of other random things I found various places that didn't work).
In both cases I have also tried signing out from all google accounts.
Now I checked a couple of webservices like Jollicloud and Odrive that tries something similar. However, both of them appear to force the user to login to google to access a file.
Is it really true that you can do all kinds of crazy things with the users files like deleting and downloading, but you can't open them in Google Docs own apps?
Not completely sure what kind of code I should add to show you what I've got. But here's some. This is my open action (what happens when the user clicks on a file and wants to open the file in the Google Docs/Sheet/etc.) (the orientdb stuff is because we're using the OrientDB graph database - it just fetches an account where we store the tokens). The link is the link property of the file (see below):
open: function(req,res,next){
var link = req.param("link");
var uid = req.param("uid");
orientdb.select().from('Account').where({uid: uid}).one()
.then(function(account){
var URL = link + "&access_token=" + account.tokens.access_token;
res.redirect(URL);
});
}
Here's an example file document from our database (I've replaced all compromising data with a descriptive
ODocument - Class: File id: #13:20499 v.6
name : Hummer2
service : Gdrive
kind : Google Doc
created : Nov 17, 2014
changed : Nov 17, 2014
users : [MB]
uid : mrb#flowtale.com
childID : <FILE.ID>
exportLinks : {DOCX=https://docs.google.com/feeds/download/documents/export/Export?id=<FILE.ID>&exportFormat=docx, Open Office doc=https://docs.google.com/feeds/download/documents/export/Export?id=<FILE.ID>&exportFormat=odt, Rich text=https://docs.google.com/feeds/download/documents/export/Export?id=<FILE.ID>&exportFormat=rtf, HTML=https://docs.google.com/feeds/download/documents/export/Export?id=<FILE.ID>&exportFormat=html, Plain text=https://docs.google.com/feeds/download/documents/export/Export?id=<FILE.ID>&exportFormat=txt, PDF=https://docs.google.com/feeds/download/documents/export/Export?id=<FILE.ID>&exportFormat=pdf}
usernames : [<ARRAY OF USERNAMES ASSOCIATED WITH THIS FILE>]
in_hasFile : User#11:0{out_hasFile:[size=2237],out_hasAccount:[size=4],username:null,email:h#h.com,password:<SOME ENCRYPTED PASSWORD>} v2244
out_belongsTo : Account#12:3{in_belongsTo:[size=6],type:Gdrive,uid:<SOME UID>,tokens:{access_token=<OUR ACCOUNT ACCESS TOKEN>, token_type=Bearer, refresh_token=<OUR ACCOUNT REFRESH TOKEN>, expiry_date=1416258913290},rootFolderID:<ROOT FOLDER ID>,email:<THE ACCOUNT EMAIL>,filesCached:2,usersCached:2,job:4,in_hasAccount:#11:0} v15
in_folderContains : File#13:20495{out_folderContains:[size=2],name:Testhest,service:Gdrive,kind:folder,created:Oct 12, 2014,changed:Oct 12, 2014,users:[1],link:https://docs.google.com/a/flowtale.com/folderview?id=<FOLDER.ID>&usp=drivesdk,uid:mrb#flowtale.com,childID:<FOLDER.ID>,exportLinks:{},usernames:[1],parents:[1],in_hasFile:#11:0,out_belongsTo:#12:3,in_folderContains:#13:13891} v36
link : https://docs.google.com/a/flowtale.com/document/d/<FILE.ID>/edit?usp=drivesdk
Looking forward to hear if anybody can help me or have experienced this before.
Thanks!
The API will allow you to do several actions in your drive account. I haven't been able to reproduce the behavior you mention with files that I haven't granted permissions to another account.
When you authenticate through the OAuth process, you will grant access to your account only to the application which created the OAuth request. You can not edit the content of a file without manually opening it through GDocs. Therefore, when the browser opens the AlternateUrl, it will require you to login to the account, in order to access the file.

Resources