i want to make a quick test to see if i can make pastebin pastes using http requests.
however i cant figure out why my script isnt working and i have tried multiple different things such as using json and ApplicationUrlEncoded but none worked and i get the same error of HTTP 422 (Unprocessable entity). if anyone could please help me that would be appreciated.
local HttpService = game:GetService("HttpService")
local url = "https://pastebin.com/api/api_post.php"
local key = 'brh'
local data = {
['api_option']= 'paste',
['api_dev_key']=key,
['api_paste_code']='dsakoawudjilawadhsa',
['api_paste_name']='test'
}
data = HttpService:JSONEncode(data)
print(data)
local response = HttpService:PostAsync(url, data)
print(response)
Please remove your dev key from this post. You should have never shared this with us
api_dev_key is supposed to be private and you should have never shared this with us.
This is a PHP resource. The data you’re sending should be url encoded. The API documentation for pastebin clarifies this. Pastebin.com - Developers API
You might’ve forgot to pass the Content-Type header since you are trying to use HttpService:PostAsync
local HttpService = game:GetService("HttpService")
local url = "https://pastebin.com/api/api_post.php"
local key = "YOUR KEY"
local paste_name = "xD hello"
local paste_data = "this is text"
local query = ("api_dev_key=%s&api_option=paste&api_paste_private=0&api_paste_name=%s&api_paste_expire_date=10M&api_paste_format=lua&api_paste_code=%s"):format(
key,
paste_name,
paste_data
)
local response = HttpService:RequestAsync({
Url = url,
Method = "POST",
Headers = {
["Content-Type"] = "application/x-www-form-urlencoded"
},
Body = query
})
print(response)
The URL to your pastebin can be accessed via response.Body
ex. here is one I generated using your key. https://pastebin.com/fC9Y6HT
i have edited my script and it worked once and now doesn’t work but i dont think i changed anything
local HttpService = game:GetService("HttpService")
local url = "https://pastebin.com/api/api_post.php"
local key = 'AAAAAAAAAA'
local paste_name = "xD hello"
local paste_data = "this is text"
local HtE = function(...) return HttpService:UrlEncode(...) end
local pasteInfo = {
api_dev_key = key,
api_option='paste',
api_paste_name = paste_name,
api_paste_code = paste_data
}
local data = ""
for i,v in pairs(pasteInfo) do
data = data .. ("&%s=%s"):format(
HttpService:UrlEncode(i),
HttpService:UrlEncode(v)
)
end
data = data:sub(2)
print(data)
local response = HttpService:PostAsync(url,data,Enum.HttpContentType.ApplicationUrlEncoded,false)
print(response)
Please also retire the API key you shared, it’s no longer safe to use. Even if you were quick enough that no one with malicious intent got hold of your key, this web page might be cached or archived somewhere. The pastebin website should allow you to do this somehow and then generate another private API key.