× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



We first used the Postman App to build/test the steps of saving a file to onedrive/teams.
Postman allowed us to make changes to the HTTP requests and test them much quicker than a program.

Once we got the requests working, we just mimicked them in RPGLE using Bradleys GETURI & some of Scott Klements IFS tools

The process is:
Get a token
Get user-id/TeamsID
Create an uploadsession
Send the file

The graph API's are used for all this and they have decent documentation for using them.

A simple upload to a persons one drive would be:

We get a token if the current one has expired.

The URL is 'login.microsoftonline.com/xxxxxxx/oauth2/v2.0/token' the xxxx I believe is specific to your site
You have to pass a client_id and client_secret with the http Post request.
We then save the token to a file to be used until it expires.

Going to a one-drive, you do a Get http request and that gets the user-id of person you are sending to
That request goes to graph.microsoft.com/v1.0/users?$filter=userPrincipalName eq 'whowesendingto@xxxxxxx'
This returns their user-id that is used in the next step.

Then create an upload session by doing a http post request to
graph.microsoft.com/v1.0/users/user-id /drive/root:/ISeries/name-of-file':/createUploadSession
This returns an URL to be used in next step

You then need to determine the length of the file you are trying to upload and we use the code below which I believe is Scott Klements

If stat(UpLoadPath: %addr(mystat)) < 0;
Endif;
p_statds = %addr(mystat);

We plug in = 'bytes 0-' + %Char(St_size - 1) + '/' + %Char(St_size) into the HTTP post request and URL is the upload path you got previously.

With Bradleys GetURI the HTTP request looks like this:

If stat(UpLoadPath: %addr(mystat)) < 0;
Endif;
p_statds = %addr(mystat);

Clear GetUri_In;
GI_URI = %Trim(Downloadurl); // this is the URL from above
GI_Port = 443;
GI_Data = '*STMF';
GI_DStmf = UpLoadPath;
GI_ReqMeth = 'PUT';
GI_SprHead = '*YES';
GI_HTTPVer = '1.1';
GI_Accept = '*/*';
GI_SSL = '*YES';
GI_NbrHdrs = 1;
GI_UsrHdr(1) = 'content-Range';
GI_UsrHdrDta(1) = 'bytes 0-' + %Char(St_size - 1) + '/' + %Char(St_size);
GI_OutType = '*STMF';
Outfile = '/tmp/iSeries/Teams/Debug/SendFile';
GI_STMF = Outfile;
GI_CCSID= 819;
GetUriRG(GetUri_In:GetUri_Out:GetUri_Head:GetUri_Data:GetUri_MsgCd:GetUri_Msg);
Clear Result6;
Monitor;
Data-into result6 %Data(outFile:'doc=file case=any allowextra=yes') %PARSER('YAJLINTO');
OneDriveLink = %Trim(Result6.webUrl);
On-Error;
Endmon;

Data-into returns a link that we then put into an email that is sent to the user to notify them they have a new document on their OneDrive.
They can click the link & they are taken directly to the document.



-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Richard Schoen
Sent: Wednesday, April 27, 2022 12:53 PM
To: midrange-l@xxxxxxxxxxxxxxxxxx
Subject: RE: Sharepoint with the system i.

Cool.

Have any sample to share to save the rest of us the learning curve of doing the graph api stuff in RPG ?

Regards,
Richard Schoen
Web: https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.richardschoen.net%2F&amp;data=05%7C01%7Csjones%40h-pproducts.com%7C06572ad9d483412b097108da286e5e8b%7C7bced1af2f3f4d99985ea8a4fce32fa5%7C0%7C0%7C637866751752895128%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=ueLdU4jCljv2TPTrd364egkyZ0cjMvElJ94ZhO61Gg4%3D&amp;reserved=0
Email: richard@xxxxxxxxxxxxxxxxx

-----Original Message-----

message: 4
date: Wed, 27 Apr 2022 16:49:45 +0000
from: "Steve M. Jones via MIDRANGE-L" <midrange-l@xxxxxxxxxxxxxxxxxx>
subject: RE: Sharepoint with the system i.

We put files out to MS-Teams and peoples One-Drive. We use the graph API's and GetURI from BVStools/Bradley Stone

It was not a difficult program to write using RPGLE

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fmidrange-l&amp;data=05%7C01%7Csjones%40h-pproducts.com%7C06572ad9d483412b097108da286e5e8b%7C7bced1af2f3f4d99985ea8a4fce32fa5%7C0%7C0%7C637866751752895128%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=1uL%2Fs68ROHh2%2BYmu2ujY27FDZ7nLrageHJGLIXkVwmI%3D&amp;reserved=0
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fmidrange-l&amp;data=05%7C01%7Csjones%40h-pproducts.com%7C06572ad9d483412b097108da286e5e8b%7C7bced1af2f3f4d99985ea8a4fce32fa5%7C0%7C0%7C637866751752895128%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=SqZHN9uWgE6aLmWRl0FiUgIIuE998Xu59xMgsi93NG0%3D&amp;reserved=0.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Famazon.midrange.com%2F&amp;data=05%7C01%7Csjones%40h-pproducts.com%7C06572ad9d483412b097108da286e5e8b%7C7bced1af2f3f4d99985ea8a4fce32fa5%7C0%7C0%7C637866751752895128%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=TEYpOgtHvR7B1p6RgVLCS2qngaN8KBftlwG76z9P4iA%3D&amp;reserved=0

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.