|
Post by noobler on May 12, 2023 20:11:11 GMT
hello everybody, i'm trying to use github rest APIs and i have a problem, accesing a file is working but creating it seems impossible for me, might be skill issue XD here what i tried and cant get it to work local function createFile(filePath, content, commitMsg, authToken)
local headers_body = {
["Authorization"] = "token " .. authToken,
["Accept"] = "application/vnd.github.v3+json",
["User-Agent"] = "LuaHTTP/0.1",
["message"] = commitMsg,
["content"] = content,
}
local url = "https://api.github.com/repos/username_example/repo_example/contents/" ..filePath
local err, Response = pcall(httpPost,url, headers_body)
if err then
print(tostring(Response))
else
print(tostring(err))
print(tostring(Response))
end
return Response
end
local filePath = "coreVersion2.lua"
local content = encodedString
local commitMsg = "Create file"
local authToken = "github_pat_token_example"
local response = createFile(filePath, content, commitMsg, authToken)
here the API doc github API doc
|
|
|
Post by noobler on May 15, 2023 17:40:34 GMT
no one? Sadge
|
|
|
Post by Exilereven on May 15, 2023 22:23:13 GMT
hello everybody, i'm trying to use github rest APIs and i have a problem, accesing a file is working but creating it seems impossible for me, might be skill issue XD here what i tried and cant get it to work local function createFile(filePath, content, commitMsg, authToken)
local headers_body = {
["Authorization"] = "token " .. authToken,
["Accept"] = "application/vnd.github.v3+json",
["User-Agent"] = "LuaHTTP/0.1",
["message"] = commitMsg,
["content"] = content,
}
local url = "https://api.github.com/repos/username_example/repo_example/contents/" ..filePath
local err, Response = pcall(httpPost,url, headers_body)
if err then
print(tostring(Response))
else
print(tostring(err))
print(tostring(Response))
end
return Response
end
local filePath = "coreVersion2.lua"
local content = encodedString
local commitMsg = "Create file"
local authToken = "github_pat_token_example"
local response = createFile(filePath, content, commitMsg, authToken)
here the API doc github API docI've never used it before but I might be able to help figure it out. Hit me up on discord Exilereven#9267
|
|
|
Post by noobler on May 17, 2023 21:19:51 GMT
so there's no way to use multipart/form-data post? we cant intsall socket libraries?
|
|
|
Post by noobler on May 24, 2023 7:21:33 GMT
AnkuLua Can you help me with something? sorry for bothering but can't figure out how to make it work I'm trying to use github APIs but i get network error whatever im trying to do here the example of what im trying to archive for encode i use dkjson.lua local function createFile(owner, repo, path, message, content, token)
local url = string.format("https://api.github.com/repos/%s/%s/contents/%s", owner, repo, path)
local headers = {
["Authorization"] = "token " .. token,
["Accept"] = "application/vnd.github.v3+json",
["User-Agent"] = "LuaHTTP/0.1",
["Content-Type"] = "application/json"
}
local body = {
message = message,
content = content,
committer = {
name = "name",
email = "name@github.com"
}
}
local requestBody = json.encode(body)
local response = httpPost(url, requestBody, headers)
return response
end
-- Example usage
local owner = "owner"
local repo = "repo"
local path = "path/to/my-file.txt"
local message = "Adding a new file"
local content = "bXkgbmV3IGZpbGUgY29udGVudHM=" -- Base64-encoded "my new file contents"
local token = "github_pat_token"
local response = createFile(owner, repo, path, message, content, token)
print(response)
|
|
|
Post by AnkuLua on May 24, 2023 8:00:00 GMT
AnkuLua Can you help me with something? sorry for bothering but can't figure out how to make it work I'm trying to use github APIs but i get network error whatever im trying to do here the example of what im trying to archive for encode i use dkjson.lua local function createFile(owner, repo, path, message, content, token)
local url = string.format("https://api.github.com/repos/%s/%s/contents/%s", owner, repo, path)
local headers = {
["Authorization"] = "token " .. token,
["Accept"] = "application/vnd.github.v3+json",
["User-Agent"] = "LuaHTTP/0.1",
["Content-Type"] = "application/json"
}
local body = {
message = message,
content = content,
committer = {
name = "name",
email = "name@github.com"
}
}
local requestBody = json.encode(body)
local response = httpPost(url, requestBody, headers)
return response
end
-- Example usage
local owner = "owner"
local repo = "repo"
local path = "path/to/my-file.txt"
local message = "Adding a new file"
local content = "bXkgbmV3IGZpbGUgY29udGVudHM=" -- Base64-encoded "my new file contents"
local token = "github_pat_token"
local response = createFile(owner, repo, path, message, content, token)
print(response) Sorry. We don't know github rest api.
|
|
|
Post by noobler on May 24, 2023 9:04:45 GMT
AnkuLua Can you help me with something? sorry for bothering but can't figure out how to make it work I'm trying to use github APIs but i get network error whatever im trying to do here the example of what im trying to archive for encode i use dkjson.lua
Sorry. We don't know github rest api. okay i don't want to discuss github APIs, just want to know if i could build headers and body and sent them separately or if i can't, how to include headers? i have to include body and headers on the same param and encode them together?
|
|