How to send API Token HTTP Request

Godot Version

4.3 dev5

Question

Hello!
How can I pass the Token value into Request?

Sample API Request:
curl
-X GET “URL”
-H “Authorization: Bearer “TOKEN””

Im using $HTTPRequest.request("URL) and cant understand how to send -H “Authorization: Bearer “TOKEN””

You’ll need to pass it in the headers parameter of the HTTPRequest.request() method. Something like:

var headers = ["Authorization: Bearer %s" % TOKEN]
$HTTPRequest.request(url, headers)
1 Like

Im trying like this:

extends Node
var url = “https://www.donationalerts.com/api/v1/alerts/donations
var token = “mySymbolsInToken”
var headers = [“Authorization: Bearer %s” % token]
func _ready():
$HTTPRequest.request_completed.connect(_on_request_completed)
$HTTPRequest.request(url, headers)

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

And got answer: *401 Unauthorized
Authentication is required and has failed or has not yet been provided

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