help with using HTTPREQUEST node

Godot Version

4.3 Stable

Question

`I’m trying to request things from modrinth using the modrinth api, but when use the code it has errors(Expected closing “)” after call arguments. , Expected end of statement after expression, found “Identifier” instead.) code : extends Node

func _ready():
$HTTPRequest.request_completed.connect(_on_request_completed)
$HTTPRequest.request(“https://api.modrinth.com/v2/search/fabric[[“categories:forge”],[“versions:1.17.1”],[“project_type:mod”],[“license:mit”]]”)

#"https://api.modrinth.com/v2/search"
#"https://api.modrinth.com/"

func _on_request_completed(result, response_code, headers, body):
var json = JSON.parse_string(body.get_string_from_utf8())
print(json)

can somebody please help me`

I think the quotes are screwing it up:

"foo["bar"]"

should be:

"foo[\"bar\"]"

You need to escape the quotes that are inside the string.

2 Likes

Yeah that looks like the problem. Alternatively, enclosing the whole string in single quotes should also work:

'foo["bar"]'

thanks but theres a new problem, the route dosen’t excist

it just doesn’t allow quotation marks in quotation marks

You use a ? instead of / after search.
This line seemed to work:
$HTTPRequest.request("https://api.modrinth.com/v2/search?fabric['categories:forge'],['versions:1.17.1'],['project_type:mod'],['license:mit']")

I say seems to because it brings up a bunch of items however the categories, licenses, versions don’t match the filters in all cases.
I am not sure why that is.