H
H
HexUserHex2020-12-18 22:41:11
PowerShell
HexUserHex, 2020-12-18 22:41:11

Powershell fetch question?

Good evening,
I am writing a simple script in Powershell, it became necessary to periodically access the API, I decided to use the fetch cmdlet (copying the fetch request from swager-a):

fetch("https://api.wigle.net/api/v2/network/detail?netid=80%3ADA%3A13%3A01%3A1D%3AB3", {
  "headers": {
    "accept": "application/json",
    "accept-language": "fr-FR,fr;q=0.9,ru-RU;q=0.8,ru;q=0.7,en-US;q=0.6,en;q=0.5",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin"
  },
  "referrer": "https://api.wigle.net/swagger",
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": null,
  "method": "GET",
  "mode": "cors",
  "credentials": "include"
});


but I get:

Unexpected token ":" in an expression or statement.
string:3 char:13
+ "accept": "application/json",


version with Invoke
Invoke-WebRequest -Uri "https://api.wigle.net/api/v2/network/detail?netid=80%3ADA%3A13%3A01%3A1D%3AB3" -Headers @{
"accept"="application/json"
  "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
  "Sec-Fetch-Site"="same-origin"
  "Sec-Fetch-Mode"="cors"
  "Sec-Fetch-Dest"="empty"
  "Referer"="https://api.wigle.net/swagger"
  "Accept-Encoding"="gzip, deflate, br"
  "Accept-Language"="fr-FR,fr;q=0.9,ru-RU;q=0.8,ru;q=0.7,en-US;q=0.6,en;q=0.5"
  "Cookie"="__ssid=93e6b9ecb065c442db3a58bb80774c7; auth=qwerty%3A730040346%3A1608316483%3ATA84tmYcjHFxRp7uV5RUXQ"
}


I tried to replace the quotes with ' or remove them completely... but the error does not go away... tell me what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew AT, 2020-12-19
@HexUserHex

$headers = 
@{
"accept"="application/json"
  "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
  "Sec-Fetch-Site"="same-origin"
  "Sec-Fetch-Mode"="cors"
  "Sec-Fetch-Dest"="empty"
  "Referer"="https://api.wigle.net/swagger"
  "Accept-Encoding"="gzip, deflate, br"
  "Accept-Language"="fr-FR,fr;q=0.9,ru-RU;q=0.8,ru;q=0.7,en-US;q=0.6,en;q=0.5"
}

$URL        = "https://api.wigle.net/api/v2/network/detail?netid=80%3ADA%3A13%3A01%3A1D%3AB3"
$WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession

$MyCookie        = New-Object System.Net.Cookie 
$MyCookie.Name   = "__ssid"
$MyCookie.Value  = "93e6b9ecb065c442db3a58bb80774c7"
$MyCookie.Domain = "api.wigle.net"
$WebSession.Cookies.Add($MyCookie)

$MyCookie        = New-Object System.Net.Cookie 
$MyCookie.Name   = "auth"
$MyCookie.Value  = "qwerty%3A730040346%3A1608316483%3ATA84tmYcjHFxRp7uV5RUXQ"
$MyCookie.Domain = "api.wigle.net"
$WebSession.Cookies.Add($MyCookie)

Invoke-WebRequest -Uri $URL -Headers $headers -WebSession $WebSession

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question