File size: 1,256 Bytes
54c3fd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

document.getElementById("otpForm").addEventListener("submit", async function(event) {
    event.preventDefault();
    
    // Capture form values
    const isd_code = document.getElementById("isd_code").value;
    const phone = document.getElementById("phone").value;
    const tenant_id = document.getElementById("tenant_id").value;
    const product_id = document.getElementById("product_id").value;

    // Construct API payload
    const payload = {
        isd_code: isd_code,
        phone: phone,
        tenant_id: parseInt(tenant_id),
        product_id: parseInt(product_id)
    };

    try {
        // Send POST request to the API
        const response = await fetch("https://otp.infinitylearn.com/api/getGatewayOtp", {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(payload)
        });

        // Parse JSON response
        const data = await response.json();
        
        // Display the response in the preformatted section
        document.getElementById("response").textContent = JSON.stringify(data, null, 2);
    } catch (error) {
        document.getElementById("response").textContent = "Error: " + error.message;
    }
});