API Endpoints
View all of our API endpoints, learn about our data structuring, and integrate your framework with Sonoran CMS.
Last updated
Was this helpful?
Was this helpful?
// Import Axios library
// https://www.npmjs.com/package/axios
// Install command: `npm i axios`
import axios from 'axios';
// Set the API URL (CMS backend)
let baseURL = 'https://api.sonorancms.com';
// Set the `api` object to be used
let api = axios.create({ baseURL });
// Format the POST body data
// https://info.sonorancms.com/developer-api-documentation/api-integration/api-endpoints/general/get-com-account
const data = {
id: 'YOUR_COMMUNITY_ID',
key: 'YOUR_API_KEY',
type: 'GET_COM_ACCOUNT',
data: [
{
apiId: "235947056630333440" // Discord ID
}
],
};
// Send the POST request
// Format the data to JSON
api.post('/general/get_com_account', JSON.stringify(data))
.then((response) => {
// Response back from the backend
console.log(response);
})
.catch((err) => {
// Error response back from the backend
console.log(err);
});-- Body payload object
local payload = {}
-- Specify our community ID, API key, and API method type (Panic)
payload["id"] = "YOUR_COMMUNITY_ID"
payload["key"] = "YOUR_API_KEY"
payload["type"] = "GET_COM_ACCOUNT"
-- Data: List (array) of unit panic objects
-- Here, we're specifying one unit to PANIC
local postData = {
{
["apiId"] = "235947056630333440", -- Discord ID
},
}
-- Add this data to our payload
payload["data"] = postData
-- Send POST request with JSON encoded body (payload)
PerformHttpRequest("https://api.sonorancms.com/general/get_com_account", function(statusCode, res, headers)
if statusCode == 200 and res ~= nil then
-- Status code 200 (Success)
print("result: "..tostring(res))
else
-- Error code
print(("CMS API ERROR: %s %s"):format(statusCode, res))
end
end, "POST", json.encode(payload), {["Content-Type"]="application/json"})