BNWEIN / CIPPAPIModule

A PowerShell Module for the CIPP API
GNU Affero General Public License v3.0
11 stars 6 forks source link

Invoke-RestMethod: Bad Request #11

Closed jmv-support closed 2 weeks ago

jmv-support commented 2 weeks ago

Description

First of all thanks for the massive effort in producing this awesome piece of work!

After installing the CIPPAPIModule 1.1.4 on Powershell 7.4.3 without issues, I can authohorize with Set-CIPPAPIDetails without issues but every command thereafter results in "Invoke-RestMethod: Bad Request" as if the api-url isn't correct. I'm 100% sure that's correct, it's copied from the response from the CIPP registration. Even the Get-CIPPLogs gives this error.

Any suggestion on how to resolve this?

Furthermore (and separate from this issue), the Get-AllTenants-SharedMailboxesEnabledAccount.ps1 has an error in line 46. The Get-CIPPEnabled[...] is missing an 's' at the end.

Environment data

Module Version Number: 1.1.4 
CIPP Back end version number: 6.0.0
BNWEIN commented 2 weeks ago

Thanks for reporting this.

Firstly, the easy one. I have updated Get-AllTenants-SharedMailboxesEnabledAccount.ps1 and this will be in the next release.

I need to investigate the latter issue. But to put your mind at ease, the issue is not PowerShell 7.4.3. It seems the issue is after the latest CIPP Update even in PowerShell 7.4.2

I will investigate this and update you shortly

BNWEIN commented 2 weeks ago

OK so after further investigation. It seems its only Get-CIPPLogs that is broken! Can you confirm that your end by trying:

Get-CIPPMailboxes -CustomerTenantID contoso.onmicrosoft.com

I will investigate the get-CIPPLogs function

BNWEIN commented 2 weeks ago

All confirmed. The issue is on CIPP's end, not on the module or your end. We will be raising a hotfix in CIPP shortly.

If you can confirm you are happy for me to close this issue now?

jmv-support commented 2 weeks ago

Thanks for the very rapid response. Much appreciated.

Your reply would indicate that your test-script would work as well.. but it doesn't. The line $tenantsList = Get-CIPPTenants gives me a Invoke-RestMethod: Bad Request So it's not just the get-CIPPLogs (in my case). I've also noticed that I do not get any errors when using wrong information on purpose in the Set-CIPPAPIDetails command. Only if I enter the wrong apiurl I get a Invoke-RestMethod: No such host is known. Any other wrong information (tenantID, secret or clientID) stays silent and without error.

So if that is part of the whole issue on CIPP's end, yeah you can close this one and I'll wait for the update.

BNWEIN commented 2 weeks ago

I just tested Get-CIPPTenants on 7.4.3 and it works fine.

image

all the Set-CIPPAPIDetails command does is essentially set some variables. Its not until you try and actually run a command to the API does the module try and connect. So its difficult to put any validation on the Set-CIPPAPIDetails function its self.

Ill see what happens when i use wrong credentials and run a command and see if i can add some validation to that

jmv-support commented 2 weeks ago

In my case: (with correct credentials)

PS C:\TACL> Get-CIPPTenants
Invoke-RestMethod: Bad Request
BNWEIN commented 2 weeks ago

This seems like a localised issue, i have tested it on several VM's and i am not seeing the same. Have you tried closing and re-opening powershell in case a var is stuck?

BNWEIN commented 2 weeks ago

Hmmm Scrap that!! I had the wrong version of the module installed. Bear with me.

jmv-support commented 2 weeks ago

I've even reinstalled Powershell and rebooted my machine several times. Nothing so far.

BNWEIN commented 2 weeks ago

OK

Get-CIPPTenants -customertenantID contoso.onmicrosoft.com

This works

get-CIPPTenants

on its own does not. and this is because of a change in how CIPP Is handling listing tenants. This will require some work to resolve but i will ensure its resolved by the next update.

jmv-support commented 2 weeks ago

That gives me a Invoke-RestMethod: Bad Request as well so I then conclude it's local. You can close this one.
Thanks for looking and the support!

BNWEIN commented 2 weeks ago

Ok it seems maybe there was a temporary issue! Maybe MS Is having some funky issues today but it seems to be working without me making any changes

image

BNWEIN commented 2 weeks ago

That gives me a Invoke-RestMethod: Bad Request as well so I then conclude it's local. You can close this one. Thanks for looking and the support!

I will close this, but i think maybe MS is having some funky issues or something! Before getting too frustrated try again in the morning because i was at points getting the same errors as you, and then trying again and it all just worked.

Def not a module issue

Also always worth checking you can call the API Directly with something simple like the below

https://docs.cipp.app/api-documentation/setup-and-authentication#authentication