Invoke-RestMethod : Unable to export as JSON - Enterprise license is missing or invalid!

Hi @gsmith, here is the new post about the Invoke-RestMethod which returns the following error message. The following is a continuation of the following post PowerShell and REST API stream search.

----------------------Displayed Error------------------------------------------------------------------
Invoke-RestMethod : Unable to export as JSON - Enterprise license is missing or invalid!
At line:5 char:6

  • $r = Invoke-RestMethod -Uri $Uri_Search -Credential $cred -Method Pos …
```

 * CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
 * FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
----------------------Displayed Error------------------------------------------------------------------



The above error is returned when the below script is run under Windows ISE.

------------------------- API Call ---------------------------
$Uri_Search = “https://lnx.server.net:9000/api/views/search/messages”
$Headers = @{ Accept = ‘application/json’; ‘X-Requested-By’ = ‘GraylogScript’ }
$r = Invoke-RestMethod -Uri $Uri_Search -Credential $cred -Method Post -ContentType ‘application/json’ -Headers $Headers -Body ‘{
“streams”: [
“6105272292dfc35e022c94b3”
],
“query_string”: {
“type”: “elasticsearch”,
“query_string”: “*”
},
“timerange”: {
“type”: “relative”,
“range”: 300
}
}’ 

Let me know if there is a solution to this or if it is expected behaviour.
1 Like

Hi @gsmith, i think i may have worked this one out. Appears that the “graylog-enterprise-plugins” were causing the license error. In my case is did a “yum remove graylog-enterprise-plugins” and restarted services. I then modified the script as shown below to call the search successfully.

------------------------- API Call ---------------------------
$Uri_Search = “https://lnx.server.net:9000/api/views/search/messages”
$Headers = @{‘X-Requested-By’ = ‘GraylogScript’ }
$r = Invoke-RestMethod -Uri $Uri_Search -Credential $cred -Method Post -ContentType ‘application/json’ -Headers $Headers -Body ‘{
“streams”: [
“6105272292dfc35e022c94b3”
],
“query_string”: {
“type”: “elasticsearch”,
“query_string”: “*”
},
“timerange”: {
“type”: “relative”,
“range”: 300
}
}’

1 Like

Hello

Well that was easy enough :laughing: Is it still working correctly?

Hi @gsmith, kinda working. So, it does work, but the endpoint being used only allows text/csv. I have reverted to /search/universal/relative, this returns the expected JSON format.

Thanks for helping!

Hello,

awesome-yes-will-ferrell

I really didn’t do much it was you :laughing:
Appreciated you posting here on how you resolved this issue. If you could make this as resolve for future searches that would be great :+1:

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