I’m trying to make this API request where it’ll create a new dev product. My issue is that I keep on getting the error failed to make donation for reason of: Header "X-CSRF-TOKEN" has unallowed character "|" in value.
As it says, It contains the “|” character inside the Token. The best thing you can do is Double-check it and if possible, Try removing it from the token by using string.match and string.sub.
The csrf token and your .ROBLOSECURITY cookie are two different things.
You can get the csrf token from the response headers if your request was declined due to a missing/expired csrf token, and your .ROBLOSECURITY should go into a different header named “Cookie”
The csrf token shouldn’t have a “|” to begin with because I’m pretty sure roblox uses tokens that only contain letters and numbers. Are you getting the token from the response headers and passing it to the headers of the new request? What does your new code look like?
(The Csrf Token is not the same as your .ROBLOSECURITY . . .)
I was talking abt the Coookie header. But which endpoint would I have to use to get the CSRF token(sorry im new to http service)
Sure thing!
local httpService = game:GetService("HttpService")
local function getUniverseId(placeId:number)
local request = httpService:RequestAsync({
Url = string.format("https://api.roproxy.com/universes/get-universe-containing-place?placeid=%.14g", placeId)
})
print(httpService:JSONDecode(request.Body).UniverseId)
return httpService:JSONDecode(request.Body).UniverseId -- decode the data from json to a table
end
local TOKEN = "my token"
game.ReplicatedStorage:WaitForChild("Donate").OnServerInvoke = function(player, amount:number)
amount = tonumber(amount)
if amount then
local universeId = getUniverseId(game.PlaceId)
local success, id = pcall(function()
local request = httpService:RequestAsync({
Url = string.format(
"https://develop.roproxy.com/v1/universes/%d/developerproducts?name=324&description=s&priceInRobux=%d",
universeId,
amount
),
Method = "POST",
Headers = {
["Cookie"] = ".ROBLOSECURITY=" .. TOKEN,
}
})
print(request.Body)
return httpService:JSONDecode(request.Body)
end)
if success and id then
return id
end
if not success then
warn(string.format("failed to make donation for reason of: %s", id))
return nil
end
end
end
Did you remove the entire thing starting from _| and ending with |_? You should only have a bunch of letters and numbers in your cookie. If you do then make sure you have the correct cookie
thanks, now everything works fine now. Thanks for all ur help
edit: for any future readers, if you can’t get ur csrf token this way, just go to the home page and inspect then search for “csrf-token” which has the csrf token.
Fyi, the token will eventually expire so you would either need to manually get it again everyday (or whenever it expires) or just do it programmatically like I already told you
Also, you should probably change the name of the variable that holds the response data from “request” to “response” so you don’t get confused later on (because it’s response data from the server, not a request)