Basic Usage
Welcome to the Gitoin API documentation! This page provides a comprehensive guide to integrating our API with your Roblox applications, enabling you to leverage our platform's features seamlessly.
Steps to Implement
Set Up HTTP Requests Enable HTTP requests in your game settings:
Go to Game Settings > Security
Enable "Allow HTTP Requests"
Roblox docs reference
Create a Server Script
In Roblox Studio, create a new Script in ServerScriptService
Copy the provided code into this script
Customize API Details Replace the placeholder values in the script:
<CAMPAIGN_ID>
: Insert your specific campaign ID<API KEY>
: Insert your provided API key
Error Handling The script includes basic error handling. You can expand on this by logging errors or implementing retry logic.
Testing Test the API call in a controlled environment before full implementation.
Send Giftoin Function (Lua)
local HttpService = game:GetService("HttpService")
local function sendGiftoin(apiUrl, apiKey, dataTable)
local jsonData = HttpService:JSONEncode(dataTable)
local headers = {
["Content-Type"] = "application/json",
["x-gft-api-key"] = apiKey
}
local requestDetails = {
Url = apiUrl,
Method = "POST",
Headers = headers,
Body = jsonData
}
local success, response = pcall(function()
return HttpService:RequestAsync(requestDetails)
end)
if success then
if response.Success then
print("Data sent successfully! Response:", response.Body)
-- Process response data here if needed
return true, response.Body
else
warn("API request failed. Status code:", response.StatusCode)
return false, response.StatusCode
end
else
warn("Failed to send data: " .. tostring(response))
return false, response
end
end
local apiUrl = "https://api.giftoin.org/v1/api-reseller/api/v1/gcm/reseller/campaign/YOUR_CAMPAIGN_ID/order"
local apiKey = "YOUR_API_KEY"
Player Join Event
Triggers when user joins the game
This API implementation uses Roblox's HttpService
to send player data to an external endpoint when a a player joins the game. Here's a breakdown of how it works:
The script uses the
Players.PlayerAdded
event to detect when a new player joins the game.When a player joins, it creates a data table containing the player's Roblox user ID.
The
sendGiftoin
function is called with this data, along with the API URL and API key.The function converts the data to JSON format and sends a POST request to the specified API endpoint.
The request includes necessary headers like Content-Type and the API key for authentication.
Error handling is implemented using pcall to catch any issues during the HTTP request.
The script prints success or failure messages based on the API response.
game.Players.PlayerAdded:Connect(function(player)
local dataTable = {
["thirdPartyUserIds"] = {
{["type"] = "roblox",
["id"] = tostring(player.UserId)}
}
}
local success, result = sendGiftoin(apiUrl, apiKey, dataTable)
if success then
print("API call successful for player:", player.Name)
else
warn("API call failed for player:", player.Name, "Error:", result)
end
end)
Was this helpful?