Last active
June 8, 2023 12:06
-
-
Save suriya/4c148dd99ccec7464938b48d84ca8daf to your computer and use it in GitHub Desktop.
Sample code for generating E-Invoices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This page contains code samples for generating E-Invoices through APIs. Refer to https://www.gstzen.in/a/generate-e-invoice-api.html for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -X POST --data-binary @input.json \ | |
| -H "Content-Type: application/json" -H "Token: de3a3a01-273a-4a81-8b75-13fe37f14dc6" \ | |
| https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -X POST --data-binary '{ "SellerDtls": {"Gstin": "27AADCG4992P1ZT"} }' \ | |
| -H "Content-Type: application/json" -H "Token: de3a3a01-273a-4a81-8b75-13fe37f14dc6" \ | |
| https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fetch('https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Token': 'de3a3a01-273a-4a81-8b75-13fe37f14dc6' | |
| }, | |
| body: JSON.stringify({ "SellerDtls": {"Gstin": "27AADCG4992P1ZT"} }) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fetch = require('node-fetch'); | |
| fetch('https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Token': 'de3a3a01-273a-4a81-8b75-13fe37f14dc6' | |
| }, | |
| body: JSON.stringify({ "SellerDtls": {"Gstin": "27AADCG4992P1ZT"} }) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Public Function CreteJsonForEInvoice() | |
| ' Replace this with your E-Invoice JSON content | |
| ' For samples, refer to https://my.gstzen.in/p/e-invoice-samples-list/ | |
| Dim requestJSON As String | |
| requestJSON = "{ \"SellerDtls\": {\"Gstin\": \"27AADCG4992P1ZT\"} }" | |
| ' The Authentication Token that you have received from GSTZen | |
| ' Replace with your token | |
| Dim token as String | |
| token = "de3a3a01-273a-4a81-8b75-13fe37f14dc6" | |
| Debug.Print requestJSON | |
| Dim responseJSON As String | |
| responseJSON = GetDataFromURL("https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/", "POST", requestJSON, token) | |
| Debug.Print responseJSON | |
| End Function | |
| Function GetDataFromURL(strUrl, strMethod, strPostData, strToken) | |
| Dim lngTimeout | |
| Dim strUserAgentString | |
| Dim intSslErrorIgnoreFlags | |
| Dim blnEnableRedirects | |
| Dim blnEnableHttpsToHttpRedirects | |
| Dim strHostOverride | |
| Dim strLogin | |
| Dim strPassword | |
| Dim strResponseText | |
| Dim objWinHttp | |
| lngTimeout = 59000 | |
| strUserAgentString = "zen_request/0.1" | |
| intSslErrorIgnoreFlags = 13056 ' 13056: ignore all err, 0: accept no err | |
| blnEnableRedirects = True | |
| blnEnableHttpsToHttpRedirects = True | |
| strHostOverride = "" | |
| strLogin = "" | |
| strPassword = "" | |
| Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1") | |
| objWinHttp.setTimeouts lngTimeout, lngTimeout, lngTimeout, lngTimeout | |
| objWinHttp.Open strMethod, strUrl | |
| If strMethod = "POST" Then | |
| objWinHttp.setRequestHeader "Content-type", _ | |
| "application/json" | |
| objWinHttp.setRequestHeader "Token", _ | |
| strToken | |
| End If | |
| If strHostOverride <> "" Then | |
| objWinHttp.setRequestHeader "Host", strHostOverride | |
| End If | |
| objWinHttp.Option(0) = strUserAgentString | |
| objWinHttp.Option(4) = intSslErrorIgnoreFlags | |
| objWinHttp.Option(6) = blnEnableRedirects | |
| objWinHttp.Option(12) = blnEnableHttpsToHttpRedirects | |
| If (strLogin <> "") And (strPassword <> "") Then | |
| objWinHttp.SetCredentials strLogin, strPassword, 0 | |
| End If | |
| On Error Resume Next | |
| objWinHttp.Send (strPostData) | |
| If ERR.Number = 0 Then | |
| If objWinHttp.Status = "200" Then | |
| GetDataFromURL = objWinHttp.responseText | |
| Else | |
| GetDataFromURL = "HTTP " & objWinHttp.Status & " " & _ | |
| objWinHttp.statusText | |
| End If | |
| Else | |
| GetDataFromURL = "Error " & ERR.Number & " " & ERR.Source & " " & _ | |
| ERR.Description | |
| End If | |
| On Error GoTo 0 | |
| Set objWinHttp = Nothing | |
| End Function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using (var httpClient = new HttpClient()) | |
| { | |
| using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/")) | |
| { | |
| // Replace with your authorization code | |
| request.Headers.TryAddWithoutValidation("Token", "de3a3a01-273a-4a81-8b75-13fe37f14dc6"); | |
| // Replace with your E-Invoice JSON data | |
| request.Content = new StringContent("{ \"SellerDtls\": {\"Gstin\": \"27AADCG4992P1ZT\"} }"); | |
| request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); | |
| var response = await httpClient.SendAsync(request); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Request request = Request.Post("https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/"); | |
| // Replace body with your JSON | |
| String body = "{ \"SellerDtls\": {\"Gstin\": \"27AADCG4992P1ZT\"} }"; | |
| request.bodyString(body,ContentType.APPLICATION_JSON); | |
| request.setHeader("Content-Type", "application/json"); | |
| // Replace the token with your authorization code | |
| request.setHeader("Token", "de3a3a01-273a-4a81-8b75-13fe37f14dc6"); | |
| HttpResponse httpResponse = request.execute().returnResponse(); | |
| System.out.println(httpResponse.getStatusLine()); | |
| if (httpResponse.getEntity() != null) { | |
| String html = EntityUtils.toString(httpResponse.getEntity()); | |
| System.out.println(html); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| include('vendor/rmccue/requests/library/Requests.php'); | |
| Requests::register_autoloader(); | |
| $headers = array( | |
| 'Content-Type' => 'application/json', | |
| 'Token' => 'de3a3a01-273a-4a81-8b75-13fe37f14dc6' | |
| ); | |
| $data = '{ "SellerDtls": {"Gstin": "27AADCG4992P1ZT"} }'; | |
| $response = Requests::post('https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/', $headers, $data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| headers = { | |
| 'Content-Type': 'application/json', | |
| 'Token': 'de3a3a01-273a-4a81-8b75-13fe37f14dc6', # Replace with your authentication code | |
| } | |
| # Read JSON input from input.json file | |
| data = open('input.json', 'rb').read() | |
| response = requests.post('https://my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/', headers=headers, data=data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Imports (var httpClient = New HttpClient()) | |
| { | |
| Imports (var request = New HttpRequestMessage(New HttpMethod("POST"), "https:'my.gstzen.in/~gstzen/a/post-einvoice-data/einvoice-json/")) | |
| { | |
| ' Replace with your authorization code | |
| request.Headers.TryAddWithoutValidation("Token", "de3a3a01-273a-4a81-8b75-13fe37f14dc6") | |
| ' Replace with your E-Invoice JSON data | |
| request.Content = New StringContent("{ \"SellerDtls\": {\"Gstin\": \"27AADCG4992P1ZT\"} }") | |
| request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json") | |
| Dim response As var = await httpClient.SendAsync(request) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment