For the life of me I can't successfully add SharePoint list items. I have in the past, now I'm stumped, using either Invoke-WebRequest or Invoke-RestMethod. I am able to update (PATCH) without issue, and can do all sorts of GET operations against the same sites, lists, items, etc.
Here's a fiddler capture of my actual HTTP POST request (Guid's fudged):
POST https://graph.microsoft.com/v1.0/sites/2df3a5af-979d-46d6-b24d-14e4e4b58aa9/lists/2252b849-53f9-4816-bc0b-d9183357c702/items HTTP/1.1
Content-Type: application/json
Authorization: Bearer eyJ0f...
User-Agent: MSGraphPSEssentials/0.4.0
Host: graph.microsoft.com
Content-Length: 537
{
"Fields": {
"AccountStatus": "Enabled",
"DisplayName": "Fictional User 1",
"UserId": "67853e89-65a9-431d-a3b1-1d60ab74dc1f",
"ADObjectGuid": "56752e89-65a9-431d-a3b1-1d61ab78dc1f",
"AccountCreated": "2019-03-12",
"AADObjectId": "8df5db8d-1d7a-4b35-b498-138eef2946fa",
"AccountType": "AD-Synced",
"ADLastLogonDate": "2020-08-25"
}
}
For each of the fields/columns shown, the content type on the SPO list is either "single line of text" or "date and time", and in either case, no data is required. There are no other columns on the list that are required (purposely while I troubleshoot this).
Can anyone spot anything obvious that would cause me to receive 400 Bad Request and the only additional info provided is "Invalid Request"
Here's a fiddler capture of an example response:
HTTP/1.1 400 Bad Request
Date: Thu, 29 Apr 2021 14:26:08 GMT
Content-Type: application/json
Cache-Control: no-cache
Transfer-Encoding: chunked
Strict-Transport-Security: max-age=31536000
request-id: 87190763-4bfe-4a88-a69e-154fd60aad81
client-request-id: 87190763-4bfe-4a88-a69e-154fd60aad81
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"East US","Slice":"E","Ring":"5","ScaleUnit":"004","RoleInstance":"BL02EPF000035AB"}}
da
{"error":{"code":"invalidRequest","message":"Invalid request","innerError":{"date":"2021-04-29T14:26:08","request-id":"87190763-4bfe-4a88-a69e-154fd60aad81","client-request-id":"87190763-4bfe-4a88-a69e-154fd60aad81"}}}
0
Finally, here are the columns as returned by successful MS Graph request to /sites/<ID>/lists/<ID>?Expand=Columns:
>$columns.columns |select Name, DisplayName, ReadOnly, Required
name displayName readOnly required
---- ----------- -------- --------
ManagerDisplayName ManagerDisplayName False False
ManagerEmail ManagerEmail False False
Ignore Ignore False False
UserId UserId False False
Title Title False False
ComplianceAssetId Compliance Asset Id True False
IgnoreReason IgnoreReason False False
ADObjectGuid ADObjectGuid False False
AADObjectId AADObjectId False False
ADLastLogonDate ADLastLogonDate False False
AADLastSignIn AADLastSignIn False False
DisabledDate DisabledDate False False
ReEnabledDate ReEnabledDate False False
JobTitle JobTitle False False
Status Status False False
ResolvedReason ResolvedReason False False
NewAADLastSignIn NewAADLastSignIn False False
AssignedLicenses AssignedLicenses False False
AADCreationType AADCreationType False False
AccountCreated AccountCreated False False
DisplayName DisplayName False False
Email Email False False
AccountType AccountType False False
NewADLastLogonDate NewADLastLogonDate False False
ID ID True False
ContentType Content Type False False
Modified Modified True False
Created Created True False
Author Created By True False
Editor Modified By True False
_UIVersionString Version True False
Attachments Attachments False False
Edit Edit True False
LinkTitleNoMenu Title True False
LinkTitle Title True False
DocIcon Type True False
ItemChildCount Item Child Count True False
FolderChildCount Folder Child Count True False
_ComplianceFlags Label setting True False
_ComplianceTag Retention label True False
_ComplianceTagWrittenTime Retention label Applied True False
_ComplianceTagUserId Label applied by True False
_IsRecord Item is a Record True False
AppAuthor App Created By True False
AppEditor App Modified By True False
My problem is 100% only with adding new items. I wish there was more helpful info in the returned error response. Note, I'm getting the same behavior if I try to do this through the $batch endpoint. Here's the error info available that way:
>$test.responses.body.Error
code message innerError
---- ------- ----------
invalidRequest Invalid request #{date=2021-04-29T14:41:34; request-id=cdf96c25-41e1-437b-9698-64389a2dc36b; client-request-id=cdf96c25-41e1-437b-9698-64389a2dc36b}
...again just 'Invalid Request' :(.
Shamefully this problem was simply the capital "F" in "Fields" in my body. It is case sensitive (evidently). "fields" solved it. I was going to delete the question, but in case it might help someone I'll leave it.
Related
I am using ADO API calls to create REPO and related governance for the branches using ADO APIs. Look my repo.yml having all API details.
While repo is created; i get 'master' & 'develop' branches out of it. But master branch setting as the Default branch. I want to make Develop branch as default. How can I do that? what is the right API for that?
---
branches:
-
master:
bypass: false
content:
- placeholder.txt
policies:
-
merge:
id: -3
isBlocking: true
isDeleted: false
isEnabled: true
settings:
allowNoFastForward: true
allowRebase: false
allowRebaseMerge: true
allowSquash: false
scope:
-
matchKind: Exact
refName: refs/heads/master
repositoryId: ~
useSquashMerge: true
type: ~
url: ""
-
approval_count:
id: -2
isBlocking: true
isDeleted: false
isEnabled: true
settings:
allowDownvotes: false
creatorVoteCounts: false
minimumApproverCount: 1
resetOnSourcePush: true
scope:
-
matchKind: Exact
refName: refs/heads/master
repositoryId: ~
type: ~
url: ""
-
build:
id: -250
isBlocking: true
isDeleted: false
isEnabled: true
settings:
buildDefinitionId: 1
displayName: "Main Pipeline"
manualQueueOnly: false
queueOnSourceUpdateOnly: true
scope:
-
matchKind: Exact
refName: refs/heads/master
repositoryId: ~
validDuration: 0
type: ~
url: ""
-
example:
id: -4
isBlocking: true
isDeleted: false
isEnabled: true
settings:
addedFilesOnly: false
filenamePatterns: []
ignoreIfSourceIsInScope: false
message: ""
requiredReviewerIds: 1
scope:
-
matchKind: Exact
refName: refs/heads/master
repositoryId: ~
type: ~
url: ""
-
develop:
bypass: true
content:
- azure-pipelines.yml
- placeholder.txt
- params.json
- .gitignore
policies: []
organization_url: "https://xxxx.visualstudio.com/"
project: CloudTeam
I would consider a follow-up call to set the branch to develop, with
PATCH https://dev.azure.com/yourOrgName/yourProject/_apis/git/repositories/yourRepoId?api-version=6.0
and request body
{
"defaultBranch": "refs/heads/develop"
}
I am learning how to use PowerShell to control a Windows 10 VM for pentesting purposes, the cmdlet Get-MpPreference has so many parameters the ones I am interested in are
DisableIntrusionPreventionSystem :
DisableIOAVProtection : False
DisablePrivacyMode : False
DisableRealtimeMonitoring : False
DisableRemovableDriveScanning : True
DisableRestorePoint : True
DisableScanningMappedNetworkDrivesForFullScan : True
DisableScanningNetworkFiles : False
Now when I type set-mppreference -DisableRealtimeMonitoring $True I expected that parameter to have a value of Ture but I does not change.
I am running PowerShell as an admin
I have webservice protected by gatekeeper(louketo-proxy). When I call protected service via ajax request it won't redirect me to login page. It's showing me message "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:3000/app-name/api/getSession. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)."
Below is the gatekeeper configuration file:
client-id: app_id
client-secret: app_secret
discovery-url: http://127.0.0.1:8080/auth/realms/app_realm
redirection-url: http://127.0.0.1:3000
upstream-url: http://127.0.0.1:8043
enable-logging: true
enable-json-logging: true
verbose: true
enable-session-cookies: true
skip-upstream-tls-verify: true
skip-openid-provider-tls-verify: true
encryption-key: enc_key
listen: 0.0.0.0:3000
secure-cookie: false
enable-logging: true
enable-json-logging: true
enable-refresh-tokens: true
enable-session-cookies: true
enable-cors: true
cors-max-age : 1000
cors-headers:
- Accept
- Content-Type
- Cache-Control
- Pragma
- X-Custom-Header
- Source
debug: true
resources:
- uri: /app/api/v5/stylesheets/key=CSS
white-listed: true
- uri: /app/api/v5/images/key=FAVICON
white-listed: true
- uri: /app/api/v5/*
Keycloak version which I am using is 10.0.2
Did you try to define some allowed CORS origins, like
cors-origins:
- '*'
to try out what happens if you allow everything?
Here is my code in golang to connect to the instagram api
if resp, err := http.PostForm("https://api.instagram.com/oauth/access_token", url.Values{"client_secret": {appSecret}, "grant_type": {"authorization_code"},
"redirect_uri": {redirectUri}, "client_id": {appId}, "code": {code},
}); err == nil {
log.Info("%s", resp)
} else {
return 500, ctr.ErrorResponse(500, err.Error())
}
and when I print out my response, I get this
&{400 Bad Request %!s(int=400) HTTP/2.0 %!s(int=2) %!s(int=0) map[Content-Length:[114] Expires:[Sat, 01 Jan 2000 00:00:00 GMT] Vary:[Cookie, Accept-Language] Pragma:[no-cache] Cache-Control:[private, no-cache, no-store, must-revalidate] Set-Cookie:[csrftoken=gUnoNsIbM8edetUJO126sp28WZmC1BuO; expires=Mon, 10-Jul-2017 16:45:38 GMT; Max-Age=31449600; Path=/] Content-Language:[en] Date:[Mon, 11 Jul 2016 16:45:38 GMT] Content-Type:[application/json]] {%!s(*http.http2clientStream=&{0xc8201a6f20 0xc82017e380 1 0xc820a26b40 {{0 0} {0xc820d12160 {0 <nil> <nil>} 0 859544035736} 0xc82022e3f0 0xc82000a0e0 <nil> <nil> 0x1f3760} true {10485760 0xc8201a6f68} {4194190 0xc8201a6f78} 114 <nil> 0xc82000b280 0xc820a26ba0 <nil> 0xc820a26c00 true false map[] 0xc820dc6078})} %!s(int64=114) [] %!s(bool=false) map[] %!s(*http.Request=&{POST 0xc82040a180 HTTP/1.1 1 1 map[Content-Type:[application/x-www-form-urlencoded]] {0xc82043b820} 234 [] false api.instagram.com map[] map[] <nil> map[] <nil> <nil>}) %!s(*tls.ConnectionState=&{771 true false 49199 h2 true [0xc8201fcd80 0xc8201fd200] [[0xc8201fcd80 0xc8201fd200 0xc820b28900]] [] [] [203 149 65 158 231 245 216 167 215 32 166 255]})}
What's going on and how can I fix it?
Both the code I was passing in and the redirectURI were wrong. The redirectURI has to match the one used in the authorization step.
Is it acceptable to just test for "truthy" in coffeescript? I'm looking for a best practice to soak up empty strings in object attributes.
Given:
obj = {
"isNull": null,
"isEmptyString": "",
"isZero": 0
}
## coffeescript
# obj.isNull? === true
# obj.isEmptyString? === false
# obj.isZero? === false
Which is safer or preferable??
# obj.isEmptyString == "truthy"
# !!obj.isEmptyString === true
I believe !! is the accepted method:
obj = {"isNull": null, "isEmptyString": "", "isZero": 0, "isValue": 1}
!!obj.isNull # false
!!obj.isEmptyString # false
!!obj.isZero # false
!!obj.isValue # true
EDIT: Possible duplicate: Easiest way to check if string is null or empty