# E-Invoice & E-WayBills: Introduction

This section outlines the JSON-based APIs provided by Octa to help you automate your e-invoicing workflows, including
the generation, retrieval, and cancellation of e-invoices & e-waybills.

## Abbreviations & References

| Term                                                                 | Description                                                                  |
| -------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| IRN                                                                  | Invoice Reference Number                                                     |
| IRP                                                                  | Invoice Registration Portal                                                  |
| [Base64 encoding](https://en.wikipedia.org/wiki/Base64)              | Method of encoding binary data in printable string                           |
| [Base64 URL encoding](https://tools.ietf.org/html/rfc4648#section-5) | Method of encoding binary data in printable string using URL safe characters |
| [e-Invoice Sandbox (NIC)](https://einv-apisandbox.nic.in)            | NIC portal of e-invoice application development                              |

## Configuration

Before using the e-invoice and e-waybill APIs, you must complete a one-time account configuration:

1. Generate API credentials from the NIC e-Invoice Portal.
2. Configure these credentials in your Octa account.

Once this setup is complete, you can begin using Octa’s e-invoicing and e-waybill APIs.

> **Warning:** Keep your NIC API credentials secure. These credentials are directly linked to your GSTIN, and any misuse could impact
> your compliance obligations.

### Step-1: Create API users on Govt e-Invoice Portal

> **Tip:** **OTP Required**: Govt e-Invoice Portal will send an OTP to the registered mobile number. This OTP is required to
> generate the API username/password. You will get the OTP on the mobile number which is registered on Govt GST Portal.

- Login to [Govt e-invoice portal](https://einvoice1.gst.gov.in)
- Goto **API Registration** → **User Credentials** → **Create API User**. System will send an OTP to registered mobile
  number. Enter the OTP to continue.
- Select the option **Through GSP**
- Select GSP: **Blowbits Solutions LLP**
- Select the API username and password
- Click **Submit**
- Repeat the process for **Alankit Limited** GSP also.

> **Tip:** **Service Availability**: Octa uses one of these API users for each request. Configuring API users for both GSPs
> allows e-invoice services to be moved to the other GSP if one GSP is down.

### Step-2: Configure API users in Octa

- Sign in at [cloud.octagst.com](https://cloud.octagst.com) and open the **Octa** app. If you don't have an account,
  please contact us for your account creation.
- On the **Companies** page, open the company you want to use for e-invoicing/e-waybills. If the company is not
  available in Octa, click the **Add Company** button, enter your GSTIN and create the company.
- In the **E-Invoicing & E-Waybills** section of the left bar, click **Configuration**, then open the **GSTINs** tab.
- For each GSTIN you want to use:
  - Edit the **E-Invoice Details** and enter the company details.
  - Edit the **IRP Accounts** and add the API credentials you generated on the Govt e-Invoice Portal in Step-1.

A GSTIN can be used with these APIs only after both are configured. For any other GSTIN, the APIs return the HTTP status
`412 Precondition Failed` with error code `153` in the `Octa-ErrorCode` header.

## Request Headers

All E-Invoice & E-Waybill APIs require the `Authorization` header. Refer
[Authentication](/octa/docs/api/overview/getting-started#authentication).

The `Octa-Company` header is not required. The GSTIN to work on is taken from the `gstin` query parameter, or from the
request payload.

## Query Parameters for Files

Several APIs can include files in the response. They use the following query parameters:

| Name            | Description                           | Value                        |
| --------------- | ------------------------------------- | ---------------------------- |
| `pdf`           | Include the PDF files in the response | `yes`, `no` (Default)        |
| `qrcode`        | Include the e-invoice QR code image   | `yes`, `no` (Default)        |
| `qrcodeformat`  | QR code image format                  | `PNG` (Default), `JPEG`      |
| `qrcodequality` | QR code image quality                 | `standard`, `high` (Default) |

## Response Format

The E-Invoice & E-Waybill APIs return a JSON payload with the HTTP status `200 OK`, both on success and on most
failures:

- `Success` is `true` if the request succeeded, and `false` if it failed.
- `Errors` lists the errors when the request failed. It can also be present when `Success` is `true`: in that case it
  holds warnings, such as an e-waybill that could not be generated along with an e-invoice. E-waybill messages start
  with `EWB: `.
- Fields that have no value are left out of the response.
- `IrnStatus` and `EwbStatus` have the values `ACT` (Active), `CNL` (Cancelled) or `DIS` (Discarded).

Each error has a `Code` and a `Message`. Refer [Error Codes](/octa/docs/api/einvoice/error-codes).

A few errors are returned as an HTTP error status, with the `Octa-ErrorCode` and `Octa-ErrorMessage` headers instead of a
JSON payload:

- `401 Unauthorized` and `403 Forbidden`: authentication errors. Refer
  [Error Handling](/octa/docs/api/overview/getting-started#error-handling).
- `412 Precondition Failed`: the GSTIN is not configured for e-invoicing in Octa (see Step-2 above).

## Billing

API calls are charged to your wallet when Octa accepts the request, before it is sent to the IRP. A call is charged
even if the IRP returns an error. Refer [Billing](/octa/docs/api/overview/getting-started#billing).

## Sandbox

If your Octa subscription is a sandbox (test) subscription, its API keys send requests to the NIC e-Invoice sandbox
instead of the live IRP. Use a sandbox subscription to test your integration before going live.