Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP/1.1 400 Bad Request when running Set-ProfileCardPronoun.ps1 #8

Open
artur-gawrych opened this issue Jun 30, 2022 · 4 comments
Open

Comments

@artur-gawrych
Copy link

Hello,

I've cloned the repo and when trying to run

.\Set-ProfileCardPronoun.ps1 -PronounAttribute extensionAttribute7

I'm getting this error message:

`Invoke-MgGraphRequest : PATCH https://graph.microsoft.com/beta/organization/626943f2-f827-4ac9-a162-0c28f72d8252/settings/profileCardProperties
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000
request-id: ***
client-request-id: ***
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"AM4PEPF0001511C"}}
Date: Thu, 30 Jun 2022 15:04:52 GMT
At C:\Users\user\OneDrive\Documents\GIT\m365-gender-pronoun-kit\src\Set-ProfileCardPronoun.ps1:46 char:11

  • $result = Invoke-MgGraphRequest -Uri $uri -Method PATCH -Body $bodyJs ...
  •       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (Method: PATCH, ...-Length: 210
      }:HttpRequestMessage) [Invoke-MgGraphRequest], HttpResponseException
    • FullyQualifiedErrorId : InvokeGraphHttpResponseException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.InvokeMgGraphRequest`

Any ideas?

@merill
Copy link
Owner

merill commented Jul 4, 2022

Can you change line 46 to include a -Debug and try running again? That should hopefully provide some additional info on why it is failing.

$result = Invoke-MgGraphRequest -Uri $uri -Method PATCH -Body $bodyJson -Debug

@artur-gawrych
Copy link
Author

artur-gawrych commented Jul 5, 2022

I was able to get it working by changing the code on line 46 to:

$result = Invoke-MgGraphRequest -Uri $uri -Method POST -Body $bodyJson

I've change PATCH to POST.

Now, I'm having some difficulties with the Invoke-PronounSync. I'm getting this error when trying to run it.

At line:1 char:1
+ Get-PnPUserProfileProperty -Account [email protected]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPUserProfileProperty], ServerUnauthorizedAccessException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.UserProfiles.GetUserProfileProperty

I've checked the API permissions and all looks good there.

@merill
Copy link
Owner

merill commented Jul 8, 2022

When you used PnPConnect did you connect with the url to SharePoint admin?

E.g.

$AdminCenterURL = "https://crescent-admin.sharepoint.com"

#Connect to Tenant Admin
Connect-PnPOnline -URL $AdminCenterURL

@artur-gawrych
Copy link
Author

I've run the Invoke-PronounSync.ps1 script.

image

.\Invoke-PronounSync.ps1 -Tenant xxx.onmicrosoft.com -Url 'https://xxx-admin.sharepoint.com' -ClientId <APPID> -Certificate '.\User Pronoun Sync App.pfx'

When trying to connect using your suggested method I got this error:

Connect-PnPOnline : AADSTS65001: The user or administrator has not consented to use the application with ID
'31359c7f-bd7e-475c-86db-fdb8c937548e' named 'PnP Management Shell'. Send an interactive authorization request for
this user and resource.

I've connected using the below command and accepted the consent to use the PnP Management Shell

Connect-PnPOnline -Url $adminurl -PnPManagementShell

While I was able to connect using Connect-PnPOnline -Url $adminurl, I am still getting the same error while running the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants