FBR Pakistan API Call
Posted: Mon Jul 07, 2025 12:14 pm
First register and get token which might take some time may be upto 2 days,
User Manual
https://download1.fbr.gov.pk/Docs/20256 ... alV1.4.pdf
Technical Document
https://download1.fbr.gov.pk/Docs/20256 ... rDIAPI.pdf
there are two instance/url/end points,
1. Sand Box (Test / Development)
Validation (just validation to check data)
https://gw.fbr.gov.pk/di_data/v1/di/val ... icedata_sb
Posting (Actual uploading of invoice)
https://gw.fbr.gov.pk/di_data/v1/di/postinvoicedata_sb
2. Production (Final / Actual)
Validation (just validation to check data)
https://gw.fbr.gov.pk/di_data/v1/di/validateinvoicedata
Posting (Actual uploading of invoice)
https://gw.fbr.gov.pk/di_data/v1/di/postinvoicedata
https://gw.fbr.gov.pk/di_data/v1/di/val ... icedata_sb
2. Posting (Actual uploading of invoice)
https://gw.fbr.gov.pk/di_data/v1/di/postinvoicedata_sb
SSL
Download SSL certifiate attached below and extract in a folder and rename it to DigiCertGlobalRootG2.crt
ACL 12C
ACL Higher than 12C
User Manual
https://download1.fbr.gov.pk/Docs/20256 ... alV1.4.pdf
Technical Document
https://download1.fbr.gov.pk/Docs/20256 ... rDIAPI.pdf
there are two instance/url/end points,
1. Sand Box (Test / Development)
Validation (just validation to check data)
https://gw.fbr.gov.pk/di_data/v1/di/val ... icedata_sb
Posting (Actual uploading of invoice)
https://gw.fbr.gov.pk/di_data/v1/di/postinvoicedata_sb
2. Production (Final / Actual)
Validation (just validation to check data)
https://gw.fbr.gov.pk/di_data/v1/di/validateinvoicedata
Posting (Actual uploading of invoice)
https://gw.fbr.gov.pk/di_data/v1/di/postinvoicedata
https://gw.fbr.gov.pk/di_data/v1/di/val ... icedata_sb
2. Posting (Actual uploading of invoice)
https://gw.fbr.gov.pk/di_data/v1/di/postinvoicedata_sb
SSL
Download SSL certifiate attached below and extract in a folder and rename it to DigiCertGlobalRootG2.crt
Code: Select all
orapki wallet create -wallet D:\app\wallet\fbr -auto_login -pwd ERPstuff_123
orapki wallet add -wallet D:\app\wallet\fbr -trusted_cert -cert D:\app\wallet\fbr\DigiCertGlobalRootG2.crt -pwd ERPstuff_123
orapki wallet add -wallet D:\app\wallet\fbr -trusted_cert -cert D:\app\wallet\fbr\fbr_gov_pk.crt -pwd ERPstuff_123
orapki wallet display -wallet D:\app\wallet\fbr -pwd ERPstuff_123
Code: Select all
BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(
acl => 'ERPstuff_FBR.xml',
description => 'FBR',
principal => 'ADMIN',
is_grant => TRUE,
privilege => 'connect'
);
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'gw.fbr.gov.pk',
lower_port => 443,
upper_port => 443,
ace => xs$ace_type(
privilege_list => xs$name_list('connect'),
principal_name => 'ADMIN',
principal_type => xs_acl.ptype_db
)
);
END;
ACL Higher than 12C
Code: Select all
BEGIN
-- Create ACL and grant CONNECT privilege
DBMS_NETWORK_ACL_ADMIN.create_acl (
acl => 'utl_http_acl.xml',
description => 'ACL to allow UTL_HTTP access to FBR API',
principal => 'ADMIN',
is_grant => TRUE,
privilege => 'connect'
);
-- Grant RESOLVE privilege
DBMS_NETWORK_ACL_ADMIN.add_privilege (
acl => 'utl_http_acl.xml',
principal => 'ADMIN',
is_grant => TRUE,
privilege => 'resolve'
);
-- Assign the ACL to the FBR host and HTTPS port
DBMS_NETWORK_ACL_ADMIN.assign_acl (
acl => 'utl_http_acl.xml',
host => 'gw.fbr.gov.pk',
lower_port => 443,
upper_port => 443
);
COMMIT;
END;
/
SELECT acl, principal, privilege, is_grant
FROM dba_network_acl_privileges
WHERE principal = 'ADMIN';
Code: Select all
DECLARE
l_url VARCHAR2(4000) := 'https://gw.fbr.gov.pk/di_data/v1/di/validateinvoicedata_sb';
--l_url VARCHAR2(4000) := 'https://gw.fbr.gov.pk/di_data/v1/di/postinvoicedata_sb';
l_token VARCHAR2(4000) := 'Bearer Your token here'; << token
l_clob_request CLOB;
l_clob_response CLOB;
BEGIN
-- Construct your JSON payload
l_clob_request := '{
"invoiceType": "Sale Invoice",
"invoiceDate": "2025-05-03",
"sellerNTNCNIC": "XXXXXX", << Your NTN same as you have entered while getting token
"sellerBusinessName": "ERPstuff",
"sellerProvince": "PUNJAB",
"sellerAddress": "Faisalabad",
"buyerRegistrationType": "Registered",
"buyerNTNCNIC": "23234567890",
"buyerBusinessName": "Buyer Company Name",
"buyerProvince": "PUNJAB",
"buyerAddress": "Lahore",
"invoiceRefNo": "",
"scenarioId": "SN002",
"items": [
{
"hsCode": "5208.1900",
"productDescription": "Item Name",
"rate": "18%",
"uoM": "Meter",
"quantity": 100.00,
"totalValues": 25606.00,
"valueSalesExcludingST": 21700.00,
"fixedNotifiedValueOrRetailPrice": 0,
"salesTaxApplicable": 3906.00,
"salesTaxWithheldAtSource": 0,
"extraTax": "",
"furtherTax": 868.00,
"sroScheduleNo": "",
"fedPayable": 0,
"discount": 0,
"saleType": "Goods at standard rate (default)",
"sroItemSerialNo": ""
}
]
}';
apex_web_service.g_request_headers.delete;
apex_web_service.g_request_headers(1).name := 'Authorization';
apex_web_service.g_request_headers(1).value := l_token;
apex_web_service.g_request_headers(2).name := 'Accept';
apex_web_service.g_request_headers(2).value := '*/*';
apex_web_service.g_request_headers(3).name := 'Accept-Encoding';
apex_web_service.g_request_headers(3).value := 'gzip, deflate, br';
apex_web_service.g_request_headers(4).name := 'Content-Type';
apex_web_service.g_request_headers(4).value := 'application/json';
-- Make the REST POST call
l_clob_response := APEX_WEB_SERVICE.MAKE_REST_REQUEST(p_url => l_url,
p_http_method => 'POST',
p_body => l_clob_request);
-- Output the response
DBMS_OUTPUT.PUT_LINE('Response:');
DBMS_OUTPUT.PUT_LINE(l_clob_response);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
END;