| Server IP : 13.126.101.145 / Your IP : 216.73.216.182 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ip-11-115-0-196 6.8.0-1039-aws #41~22.04.1-Ubuntu SMP Thu Sep 11 10:54:48 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.3.17 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/rentals_updated/wp-content/plugins/api_manager/assets/js/ |
Upload File : |
// Function to encode data into Base64
function encodeBase64(data) {
return btoa(JSON.stringify(data));
}
function sendToSAP(apiId, requestData) {
// Replace with your token fetching logic (e.g., API endpoint, session cookie)
const tokenUrl = `/api/get-token/${apiId}`; // Example token API URL
const postUrl = `/api/post-data/${apiId}`; // Example API endpoint for posting data
// First step: get the token
fetch(tokenUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer session-cookie-or-auth'
}
})
.then(response => response.json())
.then(tokenData => {
// Now post the request body with the token
const encodedBody = encodeBase64(requestData); // Encode data in Base64
return fetch(postUrl, {
method: 'POST',
headers: {
'Authorization': `Bearer ${tokenData.token}`, // Use fetched token
'Content-Type': 'application/json'
},
body: JSON.stringify({
data: encodedBody, // Base64 encoded request body
token: tokenData.token,
session: tokenData.session
})
});
})
.then(response => response.json())
.then(apiResponse => {
// Display the API response in the box
document.getElementById('response-box').innerText = JSON.stringify(apiResponse, null, 2);
})
.catch(error => {
console.error('Error:', error);
document.getElementById('response-box').innerText = 'Error occurred during the request.';
});
}