Recent searches
No recent searches

Valentin Vina
Joined Jun 11, 2024
·
Last activity Jan 13, 2025
Following
0
Followers
0
Total activity
4
Votes
0
Subscriptions
2
ACTIVITY OVERVIEW
BADGES
ARTICLES
POSTS
COMMUNITY COMMENTS
ARTICLE COMMENTS
ACTIVITY OVERVIEW
Latest activity by Valentin Vina
Valentin Vina commented,
Here's a sample using the Zendesk App Framework 2.0 with the ZAFClient
:
javascript
// Initialize the Zendesk App Framework client
const client = ZAFClient.init();
// Define the proxied endpoint relative to the proxy URL
const proxiedEndpoint = '/api/v1/auth/login';
// Define the request payload
const payload = {
username: 'user@example.com',
password: 'password123'
};
// Make the proxied POST request
client.request({
url: proxiedEndpoint,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(payload)
}).then(function(response) {
// Handle successful response
console.log('Login successful:', response);
}).catch(function(error) {
// Handle errors
console.error('Login failed:', error);
});
Node.js with Express
// server.js
const express = require('express');
const cors = require('cors');
const app = express();
// Middleware to parse JSON bodies
app.use(express.json());
// Define allowed origin (Zendesk proxy URL)
const allowedOrigin = 'https://subdomain.zendesk.com';
// Configure CORS
app.use(cors({
origin: allowedOrigin, // Allow only the Zendesk origin
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization']
}));
// Example login route
app.post('/api/v1/auth/login', (req, res) => {
const { username, password } = req.body;
// Implement your authentication logic here
if (username === 'user@example.com' && password === 'password123') {
res.json({ success: true, message: 'Login successful' });
} else {
res.status(401).json({ success: false, message: 'Invalid credentials' });
}
});
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
View comment · Posted Jan 13, 2025 · Valentin Vina
0
Followers
0
Votes
0
Comments
Valentin Vina commented,
use a function
import requests
def send_sms(ticket_id, phone_number, message):
# Step 1: Generate token
token_response = requests.post('https://example.com/generate-token', data={})
token = token_response.json().get('token')
# Step 2: Use the token to authenticate the SMS API
headers = {'Authorization': f'Bearer {token}'}
sms_response = requests.post(
'https://example.com/send-sms',
headers=headers,
data={'ticket_id': ticket_id, 'phone_number': phone_number, 'message': message}
)
return sms_response.json()
View comment · Posted Jun 11, 2024 · Valentin Vina
0
Followers
0
Votes
0
Comments