Hy everyOne,i use this code x++ to get the uploadsessionurl ,but always he give me a bad request from sharepoint ,and all parameters are correct :
var graphApiUrl = “https://graph.microsoft.com/v1.0/sites/{siteid}/drives/{driveid}/root:/Folder1/Folder2/kk.txt:/createUploadSession”;
System.Net.HttpWebRequest request;
System.Net.HttpWebResponse response;
System.Exception ex;
str responseText;
System.IO.StreamReader streamReader =null;
System.IO.Stream requestStream =null, responseStream=null;
System.Net.WebHeaderCollection httpHeader;
str uploadUrl;
try
{
new InteropPermission(InteropKind::ClrInterop).assert();
httpHeader = new System.Net.WebHeaderCollection();
request = System.Net.WebRequest::Create(graphApiUrl);
str requestBody = "{\"item\":{\"@microsoft.graph.conflictBehavior\":\"replace\",\"name\":\"kk.txt\"},\"deferCommit\":true}";
System.Byte[] requestBodyBytes = System.Text.Encoding::UTF8.GetBytes(requestBody);
request.set_KeepAlive(true);
request.set_ContentType("*/*");
httpHeader.Add("Authorization", "Bearer " + accessToken);
request.set_ContentType("*/*");
request.set_ContentLength(requestBodyBytes.get_Length());
request.set_Method("POST");
request.set_Headers(httpHeader);
requestStream = request.GetRequestStream();
requestStream.Write(requestBodyBytes, 0, requestBodyBytes.get_Length());
requestStream.Close();
// Send the request and get the response
response = request.GetResponse();
responseStream = response.GetResponseStream();
streamReader = new System.IO.StreamReader(responseStream);
str responseXml = streamReader.ReadToEnd();
streamReader.Close(); // Close stream reader after reading
responseStream.Close();
info(responseXml);
Newtonsoft.Json.Linq.JObject jsonResponse = Newtonsoft.Json.Linq.JObject::Parse(responseXml);
uploadUrl = jsonResponse.GetValue("uploadUrl").ToString();
Info(strFmt("Upload URL: %1", uploadUrl));
return uploadUrl;
If someone can help me in that i will be appreciated(by the way i don’t have the itemid or parentid, or other parameters , i just have the driveid and siteid )