Help with API request

Hey all! Wondering if someone can give me a hand with an API request - first up, it’s working perfect in Python with the following code

import requests
url = ""
payload={'data': '{"op": "showConfig", "path": []}',
         'key': 'supersecretkey'
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, verify=False)

What I want, is to do the same request in PowerShell. I’ve done the following, however it doesn’t seem to recognize my data field, throwing a non-empty data field is required error.

$uri = ""

$data = @"
    "data": '{"op": "showConfig","path": []}',
    "key": "SuperSecret"

Invoke-WebRequest -Uri $uri -SkipCertificateCheck -Body $newdata -Method POST

What am I doing wrong here?

Figured it out - for anyone stumbling on this the body needs to be formed as follows

$body = @{
    data =  '{"op": "showConfig","path": []}'
    key = "SuperSecretKey"

The other way you can do it is

$jsonbody = @{
	data = @{
		op = "showconfig"
		path = @()
	key = "superSecretkey"
} | ConvertTo-Json -Compress

Thanks for this! I’ve been eager to start playing with the API, and this is a good reminder to do so.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.