Offline DIGIPIN Geolocation Encoding and Decoding Microservice - n8n Workflow

Create a dedicated API microservice to generate and decode India's DIGIPIN geolocation codes instantly using an n8n workflow. This n8n template uses pure JavaScript Code nodes for offline processing.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Logistics Companies: Needing fast, offline coordinate-to-address mapping in India.
Developers: Seeking to build custom geolocation microservices without external API dependencies.
n8n Automation Specialists: Looking for advanced examples of using the n8n Code node for complex mathematical functions.
Organizations Utilizing n8n templates for digital address verification systems.

Overview

The DIGIPIN system is a critical geolocation tool in India for precise location sharing. This specialized n8n workflow solves the problem of needing an external, paid, or rate-limited geocoding API by implementing the full DIGIPIN generation and decoding logic entirely within JavaScript inside the n8n environment.

This robust n8n workflow operates as two distinct API endpoints, each using a unique n8n trigger Webhook. Because the core logic resides in a custom n8n node (Code node), all processing is handled locally, offering exceptional speed and reliability. Implementing this specialized n8n node setup means you can instantly convert latitude/longitude into a 10-character DIGIPIN, or convert a DIGIPIN back into precise coordinates, making this one of the most powerful geographical n8n templates available for India-focused applications.

How it Works

This automation functions via two parallel API routes, both starting with an n8n trigger Webhook:


  1. Generate DIGIPIN (Encoding):

The process begins when an HTTP GET request hits the /generate-digipin n8n trigger, passing lat and lon as query parameters.
The data flows into the DIGIPINGenerationCode n8n node, which executes the complex geographical JavaScript logic to calculate the corresponding DIGIPIN.
The flow continues to the Switch - Check for Success n8n node, which inspects the output for either a generated digipin or an error message.
Based on the check, the process responds to the original request using a success webhook response (HTTP 200) or an error webhook response (HTTP 422).


  1. Decode DIGIPIN (Decoding):

The decoding route starts with the /decode-digipin n8n trigger, expecting the digipin query parameter.
The DIGIPINDecodeCode n8n node runs the inverse JavaScript function, converting the alphanumeric DIGIPIN back into precise latitude and longitude coordinates.
* The Switch 2 - Check for Success1 n8n node handles routing. If coordinates are successfully generated, it uses Respond to Webhook - Success 2 (HTTP 200). If the DIGIPIN is invalid, it routes the error message via Respond to Webhook - Error 2 (HTTP 422).

Both paths leverage the power of the custom Code n8n node to provide a complete, self-contained geographical microservice.

Installation Guide

To start using this powerful n8n workflow, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON data and paste it directly into your n8n instance via the 'New' menu -> 'Import from JSON'.

  2. Activate the Webhooks: The two Webhook nodes (EncodeWebhook and DecodeWebhook) are already configured as an n8n trigger. Ensure your n8n instance is publicly accessible or running within a test environment.

  3. Find Your URL: After activating the n8n workflow, your specific webhook URLs will be available. If self-hosting, use your domain, e.g., https://n8n.yourcompany.com/webhook/generate-digipin.

  4. No Credentials Required: Since the core logic is pure JavaScript within the n8n node, no external API keys or credentials are required for this particular n8n template.

Node Details

This n8n workflow relies heavily on the Code node for proprietary logic and the Webhook nodes for API exposure.

EncodeWebhook & DecodeWebhook (n8n Trigger):
Function: Serves as the public API endpoints, triggering the n8n workflow.
Key Configuration: Set to Response Mode: Respond to Webhook Node and use unique paths (generate-digipin and decode-digipin).

DIGIPINGenerationCode (Code n8n node):
Function: Contains the complete JavaScript implementation of the DIGIPIN encoding algorithm. It takes lat and lon from the incoming request and generates the digipin field in the output.
Key Configuration: Contains hardcoded boundary checks for India and the 4x4 grid array (DIGIPINGRID) necessary for the recursive quadtree-like encoding.

DIGIPINDecode_Code (Code n8n node):
Function: Executes the inverse JavaScript logic to decode a provided DIGIPIN string back into decodedLatitude and decodedLongitude.
Key Configuration: Includes logic to remove hyphens and performs validation checks on the pin length and characters.

Switch - Check for Success (Switch n8n node):
Function: Controls the flow based on the result of the Code node. It routes to success if the digipin field exists, or to failure if the error field exists.
Key Configuration: Uses an 'exists' operation on key fields like {{ $json.digipin }} and {{ $json.error }} to ensure the correct webhook responder n8n node is executed.

Respond to Webhook (Respond to Webhook n8n node):
Function: Sends the final HTTP response back to the API caller. Error responders use HTTP 422, while success responders use HTTP
200.
* Key Configuration: Dynamically constructs the JSON response body to include the status, input parameters, and the generated output (DIGIPIN or coordinates).

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by

Product Manager in B2B SaaS product focused on CX management. Interested in building AI powered workflows that can automate or simplify the routine and complex tasks.

Featured*