1

I'm trying to query this API https://docs.iocparser.com/api-reference/parse-api

I'm getting a failure to resolve URL error, which makes me believe that somewhere in this line I've gone wrong with the formatting, but I can't figure out where, so any help would be appreciated.

$Request = Invoke-RestMethod -Method Post 
                 -Uri 'https://api.iocparser.com/url' 
                 -Headers @{"Content-Type" = "application/json"} 
                 -Body @{'url' = 'https://pastebin.com/raw/rgnvuYi2'} 
                 -Verbose

This is the error I'm getting back.

Invoke-RestMethod : {"status": "error", "error": "IOC Parser failed to resolve 
the given URL"}

1 Answers1

1

Explicitly convert the Body data to a JSON string. I do remember Invoke-RestMethod doing it automatically before, but in this case, it is not.

Invoke-RestMethod -Method Post -Uri 'https://api.iocparser.com/url' -Headers @{"Content-Type" = "application/json"} -Body (@{'url' = 'https://pastebin.com/raw/rgnvuYi2'} | ConvertTo-Json) -Verbose
logicaldiagram
  • 1,019
  • 11
  • 20
  • why do you need `ConvertTo-Json` in the `body`? – Nicholas Saunders Nov 18 '20 at 01:04
  • 1
    The `Body` parameter will take any datatype, but you don't have any real guarantee that it will convert it to a format the API is expecting. If the API wants data in JSON format, it's best to explicitly convert it. – logicaldiagram Nov 18 '20 at 18:03