Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "receipts": [
-- {
-- "header": {
-- "dateTimeIssued": "2022-06-13T00:34:00Z",
-- "receiptNumber": "{{receiptNumber1}}",
-- "uuid": "{{returnreceiptUuid1}}",
-- "previousUUID": "",
-- "referenceUUID": "{{receiptUuid1}}",
-- "referenceOldUUID": "",
-- "currency": "EGP",
-- "exchangeRate": 0
-- },
-- "documentType": {
-- "receiptType": "RT",
-- "typeVersion": "1.0"
-- },
-- "seller": {
-- "rin": "674859545",
-- "companyTradeName": "شركة الصوفى",
-- "branchCode": "0",
-- "branchAddress": {
-- "country": "EG",
-- "governate": "cairo",
-- "regionCity": "city center",
-- "street": "16 street",
-- "buildingNumber": "14BN",
-- "postalCode": "74235",
-- "floor": "1F",
-- "room": "3R",
-- "landmark": "tahrir square",
-- "additionalInformation": "talaat harb street"
-- },
-- "deviceSerialNumber": "Sofy123",
-- "activityCode": "4620"
-- },
-- "buyer": {
-- "type": "F",
-- "id": "313717919",
-- "name": "taxpayer 1",
-- "mobileNumber": "+201020567462",
-- "paymentNumber": "987654"
-- },
-- "itemData": [
-- {
-- "internalCode": "880609",
-- "description": "Samsung A02 32GB_LTE_BLACK_DS_SM-A022FZKDMEB_A022 _ A022_SM-A022FZKDMEB",
-- "itemType": "GS1",
-- "itemCode": "037000401629",
-- "unitType": "EA",
-- "quantity": 35,
-- "unitPrice": 247.96000,
-- "netSale": 7810.74000,
-- "totalSale": 8678.60000,
-- "total": 8887.04360,
-- "commercialDiscountData": [
-- {
-- "amount": 867.86000,
-- "description": "XYZ"
-- }
-- ],
-- "itemDiscountData": [
-- {
-- "amount": 10,
-- "description": "ABC"
-- },
-- {
-- "amount": 10,
-- "description": "XYZ"
-- }
-- ],
-- "valueDifference": 20,
-- "taxableItems": [
-- {
-- "taxType": "T1",
-- "amount": 1096.30360,
-- "subType": "V009",
-- "rate": 14
-- }
-- ]
-- }
-- ],
-- "totalSales": 8678.60000,
-- "totalCommercialDiscount": 867.86000,
-- "totalItemsDiscount": 20,
-- "extraReceiptDiscountData": [
-- {
-- "amount": 0,
-- "description": "ABC"
-- }
-- ],
-- "netAmount": 7810.74000,
-- "feesAmount": 0,
-- "totalAmount": 8887.04360,
-- "taxTotals": [
-- {
-- "taxType": "T1",
-- "amount": 1096.30360
-- }
-- ],
-- "paymentMethod": "C",
-- "adjustment": 0
-- }
-- ]
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].header.dateTimeIssued', '2022-06-13T00:34:00Z'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].header.receiptNumber', '{{receiptNumber1}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].header.uuid', '{{returnreceiptUuid1}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].header.previousUUID', ''
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].header.referenceUUID', '{{receiptUuid1}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].header.referenceOldUUID', ''
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].header.currency', 'EGP'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].header.exchangeRate', 0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].documentType.receiptType', 'RT'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].documentType.typeVersion', '1.0'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.rin', '674859545'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.companyTradeName', 'شركة الصوفى'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchCode', '0'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.country', 'EG'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.governate', 'cairo'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.regionCity', 'city center'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.street', '16 street'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.buildingNumber', '14BN'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.postalCode', '74235'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.floor', '1F'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.room', '3R'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.landmark', 'tahrir square'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.branchAddress.additionalInformation', 'talaat harb street'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.deviceSerialNumber', 'Sofy123'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].seller.activityCode', '4620'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].buyer.type', 'F'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].buyer.id', '313717919'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].buyer.name', 'taxpayer 1'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].buyer.mobileNumber', '+201020567462'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].buyer.paymentNumber', '987654'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].internalCode', '880609'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].description', 'Samsung A02 32GB_LTE_BLACK_DS_SM-A022FZKDMEB_A022 _ A022_SM-A022FZKDMEB'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].itemType', 'GS1'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].itemCode', '037000401629'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].unitType', 'EA'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].itemData[0].quantity', 35
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].itemData[0].unitPrice', '247.96000'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].itemData[0].netSale', '7810.74000'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].itemData[0].totalSale', '8678.60000'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].itemData[0].total', '8887.04360'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].itemData[0].commercialDiscountData[0].amount', '867.86000'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].commercialDiscountData[0].description', 'XYZ'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].itemData[0].itemDiscountData[0].amount', 10
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].itemDiscountData[0].description', 'ABC'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].itemData[0].itemDiscountData[1].amount', 10
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].itemDiscountData[1].description', 'XYZ'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].itemData[0].valueDifference', 20
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].taxableItems[0].taxType', 'T1'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].itemData[0].taxableItems[0].amount', '1096.30360'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].itemData[0].taxableItems[0].subType', 'V009'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].itemData[0].taxableItems[0].rate', 14
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].totalSales', '8678.60000'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].totalCommercialDiscount', '867.86000'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].totalItemsDiscount', 20
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].extraReceiptDiscountData[0].amount', 0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].extraReceiptDiscountData[0].description', 'ABC'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].netAmount', '7810.74000'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].feesAmount', 0
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].totalAmount', '8887.04360'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].taxTotals[0].taxType', 'T1'
EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'receipts[0].taxTotals[0].amount', '1096.30360'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'receipts[0].paymentMethod', 'C'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'receipts[0].adjustment', 0
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/v1/receiptsubmissions', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
END
GO
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"receipts": [
{
"header": {
"dateTimeIssued": "2022-06-13T00:34:00Z",
"receiptNumber": "{{receiptNumber1}}",
"uuid": "{{returnreceiptUuid1}}",
"previousUUID": "",
"referenceUUID":"{{receiptUuid1}}",
"referenceOldUUID": "",
"currency": "EGP",
"exchangeRate": 0
},
"documentType": {
"receiptType": "RT",
"typeVersion": "1.0"
},
"seller": {
"rin": "674859545",
"companyTradeName": "شركة الصوفى",
"branchCode": "0",
"branchAddress": {
"country": "EG",
"governate": "cairo",
"regionCity": "city center",
"street": "16 street",
"buildingNumber": "14BN",
"postalCode": "74235",
"floor": "1F",
"room": "3R",
"landmark": "tahrir square",
"additionalInformation": "talaat harb street"
},
"deviceSerialNumber": "Sofy123",
"activityCode": "4620"
},
"buyer": {
"type": "F",
"id": "313717919",
"name": "taxpayer 1",
"mobileNumber": "+201020567462",
"paymentNumber": "987654"
},
"itemData": [
{
"internalCode": "880609",
"description": "Samsung A02 32GB_LTE_BLACK_DS_SM-A022FZKDMEB_A022 _ A022_SM-A022FZKDMEB",
"itemType": "GS1",
"itemCode": "037000401629",
"unitType": "EA",
"quantity": 35,
"unitPrice": 247.96000 ,
"netSale": 7810.74000 ,
"totalSale": 8678.60000 ,
"total": 8887.04360 ,
"commercialDiscountData": [
{
"amount": 867.86000,
"description": "XYZ"
}
],
"itemDiscountData": [
{
"amount": 10,
"description":"ABC"
},
{
"amount": 10,
"description": "XYZ"
}
],
"valueDifference": 20,
"taxableItems": [
{
"taxType": "T1",
"amount": 1096.30360 ,
"subType": "V009",
"rate": 14
}
]
}
],
"totalSales": 8678.60000,
"totalCommercialDiscount": 867.86000,
"totalItemsDiscount": 20,
"extraReceiptDiscountData": [
{
"amount": 0,
"description": "ABC"
}
],
"netAmount": 7810.74000,
"feesAmount": 0,
"totalAmount": 8887.04360,
"taxTotals": [
{
"taxType": "T1",
"amount": 1096.30360
}
],
"paymentMethod": "C",
"adjustment": 0
}
]
}'
https://domain.com/api/v1/receiptsubmissions
Postman Collection Item JSON
{
"name": "2.3.8. Submit Return - Transportation",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{generatedAccessToken}}",
"type": "string"
}
]
},
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\r\n \"receipts\": [\r\n {\r\n \"header\": {\r\n \"dateTimeIssued\": \"2022-06-13T00:34:00Z\",\r\n \"receiptNumber\": \"{{receiptNumber1}}\",\r\n \"uuid\": \"{{returnreceiptUuid1}}\",\r\n \"previousUUID\": \"\",\r\n\t\t\t\t\"referenceUUID\":\"{{receiptUuid1}}\",\r\n \"referenceOldUUID\": \"\",\r\n \"currency\": \"EGP\",\r\n \"exchangeRate\": 0\r\n },\r\n \"documentType\": {\r\n \"receiptType\": \"RT\",\r\n \"typeVersion\": \"1.0\"\r\n },\r\n \"seller\": {\r\n \"rin\": \"674859545\",\r\n \"companyTradeName\": \"شركة الصوفى\",\r\n \"branchCode\": \"0\",\r\n \"branchAddress\": {\r\n \"country\": \"EG\",\r\n \"governate\": \"cairo\",\r\n \"regionCity\": \"city center\",\r\n \"street\": \"16 street\",\r\n \"buildingNumber\": \"14BN\",\r\n \"postalCode\": \"74235\",\r\n \"floor\": \"1F\",\r\n \"room\": \"3R\",\r\n \"landmark\": \"tahrir square\",\r\n \"additionalInformation\": \"talaat harb street\"\r\n },\r\n \"deviceSerialNumber\": \"Sofy123\",\r\n \"activityCode\": \"4620\"\r\n },\r\n \"buyer\": {\r\n \"type\": \"F\",\r\n \"id\": \"313717919\",\r\n \"name\": \"taxpayer 1\",\r\n \"mobileNumber\": \"+201020567462\",\r\n \"paymentNumber\": \"987654\"\r\n },\r\n \"itemData\": [\r\n {\r\n \"internalCode\": \"880609\",\r\n \"description\": \"Samsung A02 32GB_LTE_BLACK_DS_SM-A022FZKDMEB_A022 _ A022_SM-A022FZKDMEB\",\r\n \"itemType\": \"GS1\",\r\n \"itemCode\": \"037000401629\",\r\n \"unitType\": \"EA\",\r\n \"quantity\": 35,\r\n \"unitPrice\": 247.96000 ,\r\n \"netSale\": 7810.74000 ,\r\n \"totalSale\": 8678.60000 ,\r\n \"total\": 8887.04360 ,\r\n \"commercialDiscountData\": [\r\n {\r\n \"amount\": 867.86000, \r\n \"description\": \"XYZ\"\r\n }\r\n ],\r\n \"itemDiscountData\": [\r\n {\r\n \"amount\": 10,\r\n \"description\":\"ABC\"\r\n },\r\n {\r\n \"amount\": 10,\r\n \"description\": \"XYZ\"\r\n }\r\n ],\r\n \"valueDifference\": 20,\r\n \"taxableItems\": [\r\n {\r\n \"taxType\": \"T1\",\r\n \"amount\": 1096.30360 ,\r\n \"subType\": \"V009\",\r\n \"rate\": 14\r\n }\r\n ]\r\n }\r\n ],\r\n \"totalSales\": 8678.60000,\r\n \"totalCommercialDiscount\": 867.86000,\r\n \"totalItemsDiscount\": 20,\r\n \"extraReceiptDiscountData\": [\r\n {\r\n \"amount\": 0,\r\n \"description\": \"ABC\"\r\n }\r\n ],\r\n \"netAmount\": 7810.74000,\r\n \"feesAmount\": 0,\r\n \"totalAmount\": 8887.04360,\r\n \"taxTotals\": [\r\n {\r\n \"taxType\": \"T1\",\r\n \"amount\": 1096.30360\r\n }\r\n ],\r\n \"paymentMethod\": \"C\",\r\n \"adjustment\": 0\r\n }\r\n ]\r\n \r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{apiBaseUrl}}/api/v1/receiptsubmissions",
"host": [
"{{apiBaseUrl}}"
],
"path": [
"api",
"v1",
"receiptsubmissions"
]
}
},
"response": [
]
}