Below is the error and the code I have for uploading files in SharePoint Library. I am trying to upload it in a folder inside a document library. It works fine if I am uploading it in root level of library but gives below error while uploading it in a folder Releae342 inside a library. Any clue what is wrong here? This api do not require any JSON content
Code for upload:
Function GET-UPLOADLINK
{
param($clientId, $clientSecret, $artifactname)
$tokenObject = GET-TOKEN -clientId $clientId -clientSecret $clientSecret
$uploadLinkRequestHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$uploadLinkRequestHeaders.Add("Content-Type", "application/json")
$uploadLinkRequestHeaders.Add("Authorization", "Bearer "+ $tokenObject.access_token)
$uploadLinkRequestBody = ""
$artifactname = "test"
$fullname = "https://graph.microsoft.com/v1.0/sites/$($SPid)/drives/$($LibId)/root:/Release342/"
$comname = $fullname + $artifactname
$uploadLinkResponse = Invoke-RestMethod "$($comname).zip/createUploadSession" -Method 'POST' -Headers $uploadLinkRequestHeaders -Body $uploadLinkRequestBody
$uploadLinkResponse | ConvertTo-Json
return $uploadLinkResponse
}
Error Received:
Invoke-RestMethod : {
2020-12-10T14:41:58.9122308Z "error": {
2020-12-10T14:41:58.9122643Z "code": "BadRequest",
2020-12-10T14:41:58.9123035Z "message": "Empty Payload. JSON content expected.",
2020-12-10T14:41:58.9124293Z "innerError": {
2020-12-10T14:41:58.9124899Z "date": "2020-12-10T14:41:58",
2020-12-10T14:41:58.9125415Z "request-id": "d58a3213-cb8c-4e95-aac2-a076d36f88d9",
2020-12-10T14:41:58.9125886Z "client-request-id": "d58a3213-cb8c-4e95-aac2-a076d36f88d9"
2020-12-10T14:41:58.9126535Z }
2020-12-10T14:41:58.9126848Z }
Related
What is the right format of the Response for Kinesis Firehose with http_endpoint as destination. Have already gone through the aws link:
https://docs.aws.amazon.com/firehose/latest/dev/httpdeliveryrequestresponse.html#responseformat
I have used the below lambda code in python(integrated in api) as well as with many other options, but keep getting the below error message. The test is performed using the "Test with Demo Data" option
sample code:
def lambda_handler(event, context):
data ={}
headersD = {}
headersD['content-length'] = 0
headersD['content-type'] = 'application/json'
data['requestId'] = 'ed4acda5-034f-9f42-bba1-f29aea6d7d8f'
data['timestamp'] = '1578090903599'
bodyDetail= {}
data['body'] = ''
data['headers'] =headersD
data['statusCode']=200
resp = json.dumps(data)
return resp
error response as seen in the logs:
The response received from the endpoint is invalid. See Troubleshooting HTTP Endpoints in the Firehose documentation for more information. Reason:. Response for request 'request-Id' is not recognized as valid JSON or has unexpected fields. Raw response received: 200 "HttpEndpoint.InvalidResponseFromDestination"
Here is the sample output that worked(in python):
responseBody = {
"requestId": "requestId",
"timestamp": 123456
}
resp = {
"headers": {"Content-Type": "application/json", "Content-Length": 100},
"body": json.dumps(responseBody),
"statusCode": 200
}
return resp
the first try catch works, he is adding the ms graph AD group in office365.
But the second try catch (converting the group to a Team does not work. I receive an 404 error??
The groupID exists on the server I notice.
Whats going wrong to get an 404?
I did add a secret token on the azure control panel.
The script has the token, appid and tenantid in live time.
also: the tenant has graph roles like group.ReadWriteAll. same for Teams and Directories.
Clear-Host
$env:graphApiDemoAppId = "" # Replace with your Azure AD app id
$env:graphApiDemoAppSecret = "" # Replace with your Azure AD app secret
$env:tenantId = "" # Replace with your Azure AD tenant ID
$oauthUri = "https://login.microsoftonline.com/$env:tenantId/oauth2/v2.0/token"
# Create token request body
$tokenBody = #{
client_id = $env:graphApiDemoAppId
client_secret = $env:graphApiDemoAppSecret
scope = "https://graph.microsoft.com/.default"
grant_type = "client_credentials"
}
# Retrieve access token
$tokenRequest = Invoke-RestMethod -Uri $oauthUri -Method POST -ContentType "application/x-www-form-urlencoded" -Body $tokenBody -UseBasicParsing
# Save access token
$accessToken = ($tokenRequest).access_token
$headers = #{
"Authorization" = "Bearer $accessToken"
"Content-type" = "application/json"
}
try
{
# Create group request body
$groupName = "Test_Kenvh16"
$groupBodyParams = #{
displayName = $groupName
description = $groupName
mailNickName = $groupName
groupTypes = #("Unified")
mailEnabled = $true
securityEnabled = $false
visibility = "Private"
}
$groupBody = ConvertTo-Json -InputObject $groupBodyParams
$newGroup = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/groups" -Method POST -Headers $headers -Body $groupBody
$groupId = $newGroup.id
Write-Host "group created:" $groupName "id:" $groupId
try
{
#convert group to team..
$teamBodyParams = #{
memberSettings = #{
allowCreateUpdateChannels = $true
}
messagingSettings = #{
allowUserEditMessages = $true
allowUserDeleteMessages = $true
}
funSettings = #{
allowGiphy = $true
giphyContentRating = "strict"
}
}
$teamBody = ConvertTo-Json -InputObject $teamBodyParams
$teamUri = "https://graph.microsoft.com/v1.0/groups/" + $groupId + "/team"
$newTeam = Invoke-RestMethod -Uri $teamUri -Method POST -Headers $headers -Body $teamBody
$teamId = $newTeam.id
}
catch
{
Write-Host "createTeam ExceptionMessage:" $_.Exception.Message
Write-Host "createTeam StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "createTeam StatusDescription:" $_.Exception.Response.StatusDescription
}
}
catch
{
Write-Host "createGroup ExceptionMessage:" $_.Exception.Message
Write-Host "createGroup StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "createGroup StatusDescription:" $_.Exception.Response.StatusDescription
}
I've successfully posted a message to a Teams channel using the Micorosoft.Graph.GraphServiceClient (version 3.14). However I would like to include an image attachment (via ChatMessageAttachment). According to the documentation in order to do this I should set the ChatMessageAttachment.ContentType to "image/jpeg" and set the ContentUrl to a base64 string representation of the image file. Here is my code:
var chatMessage = new ChatMessage
{
Subject = subject,
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = message // Including <attachment id="<imageId>"></attachment>
}
};
chatMessage.Attachments = new List<ChatMessageAttachment>
{
new ChatMessageAttachment
{
Id = imageId,
ContentType = "image/jpeg",
ContentUrl = base64String,
Name = "HunnySuckle.jpg"
}
};
var res = await graphClient.Teams[teamId].Channels[channelId].Messages
.Request()
.AddAsync(chatMessage);
However when I post the request the response is 500 with the follwing body:
{
"error": {
"code": "InternalServerError",
"message": "Failed to process request.",
"innerError": {
"date": "2020-09-18T20:39:46",
"request-id": "44143c44-1c48-4a90-9bb5-20a3ba1b9905",
"client-request-id": "44143c44-1c48-4a90-9bb5-20a3ba1b9905"
}
}
}
This is the extract from the docs (https://learn.microsoft.com/en-us/graph/api/resources/chatmessageattachment?view=graph-rest-1.0)
contentType . . image/: Image type with the type of the image
specified ex: image/png, image/jpeg, image/gif. Populate the
contentUrl field with the base64 encoding of the file in data: format.
However I'm not sure what "in data: format" means - maybe this could be the key to why it's not working.
The only other reference this error that I've found by searching online is on this page: https://github.com/microsoftgraph/microsoft-graph-docs/issues/7211 which is the same problem as mine I think (but sadly no answer).
I am trying to dismiss/close risk events using an automated process. For this we would need to make use of Graph API https://graph.microsoft.com/beta/riskyUsers/dismiss
I did searched for examples and couldn't find any.
I did tried using Post man by providing OAuth Bearer token in the header and I did tried with a PowerShell script and I also tried with .Net example provided in the page. None of them worked
PowerShell Code
{
$body = #{grant_type="client_credentials";resource=$resource;client_id=$ClientID;client_secret=$ClientSecret}
$oauthResponse = Invoke-RestMethod -Method POST -Uri $loginURL/$TenantName/oauth2/token?api-version=1.0 -Body $body
return $oauthResponse
}
$loginURL = "https://login.windows.net"
$resource = "https://graph.microsoft.com"
$ClientSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$ClientID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$TenantName="xxxxx.com"
$oauth=RefreshToken -loginURL $loginURL -resource $resource -ClientID $ClientID -clientSecret $ClientSecret -tenantName $TenantName
$headerParams = #{'Authorization'="$($oauth.token_type) $($oauth.access_token)"}
$url="https://graph.microsoft.com/beta/riskyUsers/dismiss"
$userIds=#()
$userIds+="xxxxx-xxxxx-xxxxx-xxxxx-xxxxx"
$body=(#{"userIds"=$userIds})|convertto-json
$Response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Body $body -Method Post -ContentType "application/Json"
Response:
Invoke-WebRequest : The remote server returned an error: (500) Internal Server Error.
At C:\SourceCode\MIMSolution\PowerShellScripts\AzurePSMA\RiskyIdentityEvents\ExportScript_debug.ps1:19 char:13
+ $Response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
C# Code:
static void Main(string[] args)
{
var userIdsList = new List<String>();
userIdsList.Add("xxxxx-xxxxx-xxxxx-xxxxx-xxxx");
dismissUser(userIdsList);
}
static async void dismissUser(List<string> userIDs)
{
ClientCredential clientCredential = new ClientCredential("xxxxxxxxxxxxxxxxxxxxxxx");
string clientId = "xxxxxxxxxxxxxxxxxxxxxx";
IConfidentialClientApplication clientApplication = ClientCredentialProvider.CreateClientApplication(clientId, clientCredential);
ClientCredentialProvider authProvider = new ClientCredentialProvider(clientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
await graphClient.RiskyUsers.Dismiss(userIDs).Request().PostAsync();
}```
Exception:
{"Code: generalException\r\nMessage: An error occurred sending the request.\r\n"}
Inner Exception:
{"Code: generalException\r\nMessage: Unexpected exception occured while authenticating the request.\r\n"}
Finally after multiple trails , I have figured out the solution:
Issue was with the token which as OAuth 1.0 earlier.
I did fixed this snippet that request OAuth 2.0 and the issue resolved:
function RefreshToken($loginURL,$ClientID,$clientSecret,$tenantName)
{ $body = #{grant_type="client_credentials";client_id=$ClientID;client_secret=$ClientSecret;scope="https://graph.microsoft.com/.default"}
$oauthResponse = Invoke-RestMethod -Method POST -Uri $loginURL/$TenantName/oauth2/v2.0/token -Body $body
return $oauthResponse
}
While creating Notebook in MS365 authorized account via REST api call .I am facing some issue ,could anyone let me know what changes I have to make for this.
Request:
POST - https://graph.microsoft.com:443/v1.0/me/notes/notebooks
Body : {
"name": "MSOneNoteBusiness_OSSA_5LyC"
}
Response
Body : {
"error": {
"code": "BadRequest",
"message": "Unsupported segment type. ODataQuery: users/8dc0a74f-0aa6-45f4-813b-92e910f40bd4/notes/notebooks",
"innerError": {
"request-id": "fa409682-5395-4189-a43c-757adcfaea35",
"date": "2017-06-28T10:08:06"
}
}
The request should be POST https://graph.microsoft.com/v1.0/me/onenote/notebooks, not /me/notes, and the request body should have the property displayName. We also have a sample for this in the Graph Explorer: