Group Ranking (promotions)

local event = game.ReplicatedStorage.API.SendUserId
event.OnServerEvent:Connect(function(player,userId)
local server = require(workspace.API)
local domain = '(domainlink-removed)' 
local key = '(key-removed)'
local apisettings = require(workspace.APISettings)
local groupId = apisettings.groupId()
local api = server(domain, key, groupId)
print(api.promote(userId).message)
print(api.message(userId, 'Subject', 'Body').message)
print(api.getBlurb(1).data.blurb)
end)

Hmmm, maybe try putting in api.promote(groupId, userId) and see if that works.

nope, still wont work.

local event = game.ReplicatedStorage.API.SendUserId

event.OnServerEvent:Connect(function(player,userId)

local server = require(workspace.API)

local domain = 'roblox.com'

local key = 'okboomrt'

local apisettings = require(workspace.APISettings)

local groupId = apisettings.groupId()

local api = server(domain, key, groupId)

print(api.promote(groupId, userId).message)

print(api.message(userId, 'Subject', 'Body').message)

print(api.getBlurb(1).data.blurb)

end)

Give me 10 minutes and I’ll find what I used when I did this a while back then reply with a working script. The module is probably just outdated.

Try changing groups.promote to module.promote in the module script. Seems like that was all I did.

Nope.

Mind if you give me copy of your module? as you could of done some heavy redoing.

That is really all I did of importance. Is your groupId valid?

yes

(may be asking why is there and settings module?, Well one my Open-Sourced community sources app center working on the promotion system for admin panel)

image

I am deleteing groups = {}
and replacing everything saying groups to module.

In your APISettings module you aren’t returning anything just creating a local variable and if that’s the actual code then that is probably why it isn’t working. Return the id instead.

I got a new error.

Code:


local module = {}
local setmetatable = setmetatable
local error = error
local wait = wait
local httpService = game:GetService'HttpService'
local postAsync = httpService.PostAsync
local getAsync = httpService.GetAsync
local jsonEncode = httpService.JSONEncode
local jsonDecode = httpService.JSONDecode
local base, key

local function encode (tab)
  return jsonEncode(httpService, tab)
end

local function decode (tab)
  return jsonDecode(httpService, tab)
end

local function request (url, method, suppress, data)
  local body = method(httpService, url, data)
  local success, response = pcall(decode, body)
  local err
  if success then
    err = response.error
  else
    err = 'Response was not valid json, full body: '..body
  end
  if not err and suppress then
    return true, response
  elseif not err then
    return response
  elseif suppress then
    return false, err
  else
    error(err)
  end
end

local http = {
  post = function (path, data, suppress)
    if not data then
      data = {}
    end
    data.key = key
    return request(base..path, postAsync, suppress, encode(data))
  end,
  get = function (path, suppress)
    return request(base..path, getAsync, suppress)
  end
}

function module.promote (group, userId)
  return http.post('/promote/'..group..'/'..userId)
end

function module.demote (group, userId)
  return http.post('/demote/'..group..'/'..userId)
end

function module.setRank (group, userId, rank)
  return http.post('/setRank/'..group..'/'..userId..'/'..rank)
end

function module.shout (group, message)
  return http.post('/shout/'..group, {message = message})
end

function module.post (group, message)
  return http.post('/post/'..group, {message = message})
end

function module.handleJoinRequest (group, username, accept)
  local acceptString = accept and 'true' or 'false'
  return http.post('/handleJoinRequest/'..group..'/'..username..'/'..acceptString)
end

function module.getPlayers (group, rank, limit, online)
  local job = http.post('/getPlayers/make/'..group..(rank and '/'..rank or '')..'?limit='..(limit and limit or '-2')..'&online='..(online and 'true' or 'false')).data.uid
  local complete, response = false
  repeat
    wait(0.5)
    local success
    success, response = http.get('/getPlayers/retrieve/'..job, true)
    if not success and response:match('$Response was not valid json') then
      error(response)
    elseif success then
      complete = response.data.complete
    end
  until complete
  return response
end

function module.message (userId, subject, message)
  return http.post('/message/'..userId, {subject = subject, body = message})
end

function module.getBlurb (userId)
  return http.get('/getBlurb/'..userId)
end

return function (domain, newKey, group)
  local isString = (type(domain) == 'string')
  if (not domain) or (not isString) or (isString and #domain <= 0) then
    error('Url is required and must be a string greater than length 0')
  end
  isString = (type(newKey) == 'string')
  if (not newKey) or (not isString) or (isString and #newKey <= 0) then
    error('Key is required and must be a string greater than length 0')
  end

  base = 'http://'..domain
  key = newKey

  if group then
    local isNumber = (type(group) == 'number')
    if (not isNumber) or (group <= 0) then
      error('If group is provided it must be a number greater than 0')
    end

    for name, func in next, module do
      module[name] = function (...)
        return func(group, ...)
      end
    end
    return module
  end

  for name, func in next, module do
    module[name] = func
  end
  return module
end

That is still the same error. Did you do what I said with your APISettings?

oh no, Let me do that right now.

Results:
image
image
(game not published but http is enabled)

Did you put in your domain correctly? Go to Share → Live App and copy the first link there then get rid of the https:// if you haven’t done so already.

i did.

image

do it be private or public as I have it private

Then are there errors on the glitch side of things? You can check by going to the glitch project, clicking tools, and then clicking logs.

ERROR
Bad cookie.

5:12 PM

TypeError: Cannot read property ‘1’ of null

5:12 PM

at http.then (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/noblox.js/4.2.6/node_modules/noblox.js/lib/util/relog.js:40:85)

5:12 PM

at tryCatcher (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/util.js:16:23)

5:12 PM

at Promise._settlePromiseFromHandler (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/promise.js:547:31)

5:12 PM

at Promise._settlePromise (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/promise.js:604:18)

5:12 PM

at Promise._settlePromise0 (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/promise.js:649:10)

5:12 PM

at Promise._settlePromises (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/promise.js:729:18)

5:12 PM

at _drainQueueStep (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/async.js:93:12)

5:12 PM

at _drainQueue (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/async.js:86:9)

5:12 PM

at Async._drainQueues (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/async.js:102:5)

5:12 PM

at Immediate.Async.drainQueues [as _onImmediate] (/rbd/pnpm-volume/06ee5343-061c-4f85-afef-4a2dcf56db4c/node_modules/.registry.npmjs.org/bluebird/3.7.2/node_modules/bluebird/js/release/async.js:15:14)

5:12 PM

at runCallback (timers.js:705:18)

5:12 PM

at tryOnImmediate (timers.js:676:5)

5:12 PM

at processImmediate (timers.js:658:5)

Well there you go, bad cookie. You need to put a valid cookie inside of settings.json for it to work.

I inserted the roblosecurity cookie if Im wrong what cookie?
image

If you’re using chrome, go to dev tools (ctrl + shift + i) then go to the Network tab. Turn on preserve log, load a Roblox page, then click where it says the name of the page you just loaded in the list. In headers copy everything it says under cookie and paste that.

I cant find anything saying Cookie