Wednesday, 7 October 2026

API Connection Check if Live or Not

 const token = $v('P12_TOKEN');

fetch('https://gw.fbr.gov.pk/di_data/v1/di/postinvoicedata', {

    method: 'POST',

    headers: {

            'Authorization': `Bearer ${token}`,

            'Content-Type': 'application/json'

        },

    body: JSON.stringify({

        // Dummy data for API Testing

        test: true

    })

})

.then(response => {

    // Agar server response de raha hai (chahe 200 ho ya 400 Bad Request)

    console.log('Status Code:', response.status);

    return response.json().catch(() => ({})); //  Safe Fallback if JSON Not Available

})

.then(data => {

    console.log('API Response:', data);

    apex.message.alert('API is Live and Responding!');

})

.catch(error => {

    // This will Run if  network or  API is down/unreachable

    apex.message.alert('Alert: FBR API Not Responding / Network Error..!');

    console.error('Error:', error);

});

No comments:

Post a Comment

Check Internet Connectivity on Local System

if (!navigator.onLine) {     showOfflineAlert(); } else {     // Set a strict 3-second network timeout threshold     const controller = new ...