How can I access the API with a PowerShell script using the Invoke-WebRequest command?

The purpose of our Developer APIs is to allow customers to integrate our products into their own. In order to access the API with a PowerShell script using the Invoke-WebRequest command, run the command below.

This example assumes a Customer ID (CID) of 12345, as well as the Denver data center API endpoint. It fetches a list of all sources from the Log Manager API.

The username and the password string are for creating a basic HTTP authentication header. It will convert the username (API Key) and the password (blank) into a string separated by a colon, and base64-encodes it all. For our Cloud Defender APIs, the username is equivalent to your API key and the password should be a blank value.

The way that this information is passed to the Cloud Defender API is via an HTTP Header. The header requires the username and password to be separated by a colon. This entire string of text is then base64-encoded. This is a way of representing text that is a normal part of Basic HTTP Authentication.

The end of the process converts the authentication header from JSON into a PowerShell object and then returns it to JSON to ensure a clean PowerShell console response. Use the example script below to guide you.

Note: For the remote host below, the base URL will change depending on the data center you are connecting to.