Invoke-Restmethod - intermittent unauthorized error with certificate option RRS feed

  • Question

  • [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    $Uri = 'https://somerandomserver.com'
    $Store = New-Object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::My, "localmachine")
    $Certificate = $Store.Certificates | Where-Object Thumbprint -EQ "xxxxxxx"
    Invoke-RestMethod `
    -Certificate $Certificate `
    -ContentType 'application/json' `
    -Uri $uri

    I have configured access to the apiand trying to access the apiusing the certificate configured with. It is throwing unauthorized error intermittently, Am I missing something when passing the parameters to invoke-restmethod?

    Wednesday, June 17, 2020 1:53 PM

All replies

  • ERROR :: The remote server returned an error: (401) Unauthorized. 
    Wednesday, June 17, 2020 3:16 PM
  • Have you had time to look at example 3 in "get-help Invoke-RestMethod -examples"? It says "APIs often require passed headers for authentication, validation etc.".

    Tuesday, June 23, 2020 10:02 AM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Yang Yang

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, July 3, 2020 5:41 AM