Google Apps Script API Wrapper

Using Apps Scripts we create a simple endpoint API wrapper for our eSIM API
API Wrapper

Overview 

In the age of travel, remote work, and connected devices, eSIMs allow you to switch carriers and data plans on the fly—no physical SIM required. This post shows you how to build a custom API on top of eSIMAccess using Google Apps Script. You’ll be able to:

  • Fetch a user’s balance.
  • List available eSIM packages.
  • Order new packages or top-ups.
  • Query existing eSIMs by iccid or orderNo.
  • Cancel an eSIM.

Everything is wrapped in an easy-to-deploy Google Apps Script “Web App” that you can share with colleagues or customers.

Why Google Apps Script? 

Google Apps Script lets you build server-like functionality without spinning up your own server. Benefits include:

  • Fast deployment: one click to publish your web app.
  • Zero server hosting costs: runs on Google’s infrastructure.
  • Easy integration: you can tie it into Google Sheets, Docs, or simply provide a Web App URL.

We’ll rely on UrlFetchApp to talk to the eSIMAccess API, transform data, and return JSON responses.

Project Setup 

  • Create a new Google Apps Script project:
  • Copy the script code into that file.
  • Replace the placeholder “YOUR_ACCESS_CODE” with your real RT-AccessCode from eSIMAccess.
  • Deploy as a Web App:
    • In the editor, click Deploy > New deployment.
    • Select Web app as the deployment type.
  • Execute as: your Google account.
  • Who has access: “Anyone” if you want a public endpoint.
  • Get the Postman JSON file here.
  • Use the Google url in postman as your GET endpoint

Endpoints & Usage

Once you have deployed your Google Apps Script as a Web App, you will receive a unique URL, for example:

https://script.google.com/macros/s/YOUR_SCRIPT_ID/exec

Append different query parameters to this URL to call various functionalities of your eSIM integration:

5.1 Check Balance

No parameters in the query string.

GET https://SCRIPT_URL/exec

Sample JSON response:

{
  "balance": "$126.98"
}

5.2 List a Package by Slug

Provide slug in the query string. No qty means you are just requesting details about a package.

GET https://SCRIPT_URL/exec?slug=US_1_7

Sample JSON response (single package object):

{
  "packageCode": "US_1_7",
  "price": 9.0,
  "volume": 1,
  "duration": 7,
  "durationUnit": "DAY",
  ...
}

5.3 Order a Package

Provide slug and qty. Optionally, days to set the period number. This calls the eSIM “order” API to purchase a data package.

GET https://SCRIPT_URL/exec?slug=US_1_7&qty=1&days=7

Sample JSON response:

{
  "orderNo": "B25012220580005",
  "transactionId": "gs_1674601154085"
}

5.4 Query eSIM Details

Provide either iccid or orderno. This calls the eSIM “query” API and returns a single eSIM record.

GET https://SCRIPT_URL/exec?iccid=8943108170005579276

OR

GET https://SCRIPT_URL/exec?orderno=B25012220580005

Sample JSON response:

{
  "iccid": "8943108170005579276",
  "smsStatus": 1,
  "msisdn": "4367844378927",
  "packageList": [
    {
      "packageName": "Spain 1GB 7Days",
      "slug": "ES_1_7",
      ...
    }
  ],
  ...
}

5.5 Top-Up

If you set action=topup and include either slug or iccid (but no qty), it lists available top-up packages. If you also provide qty, it orders a top-up.

Example 1: List Top-Up Packages by ICCID

GET https://SCRIPT_URL/exec?action=topup&iccid=89852350924060003915

Example 2: List Top-Up Packages by Slug

GET https://SCRIPT_URL/exec?action=topup&slug=ES_1_7

Example 3: Order a Top-Up

GET https://SCRIPT_URL/exec?action=topup&iccid=89852350924060003915y&slug=ES_1_7&qty=1

Sample top-up order response:

{
  "orderNo": "B25012220580006",
  "transactionId": "gs_1674601154090"
}

5.6 Cancel an eSIM

Provide action=cancel and iccid to call the “cancel” API. If it succeeds, you’ll get a simple success message.

GET https://SCRIPT_URL/exec?action=cancel&iccid=8943108170005579276

Sample JSON response:

{
  "success": true
}

That’s it! With these endpoints, you can perform all the major eSIM operations—balance checks, package listings, orders, queries, top-ups, and cancellations—directly through your Google Apps Script Web App URL.

Security Considerations 

ACCESS_CODE: The RT-AccessCode is stored as a global ACCESS_CODE in this script. If you share the script with others as Editor, they can see it. For a production scenario, you might store the token in an Apps Script Property Store.

Public vs. Private: If you deploy with “Anyone” access, any user with the URL can call it. They’ll all use your RT-AccessCode. Consider restricting access or adding your own authentication layer.

Logging: Note that query parameters are typically logged in browser history or logs. If you have to pass sensitive data, consider using a doPost(e) approach with a JSON body to hide secrets from the URL.

Wrapping Up 

With this Google Apps Script:

  • You can quickly check eSIM data—like user balances or available packages.
  • Easily purchase or top-up eSIMs for global data usage.
  • Cancel eSIMs if needed.

This flexible approach gives you a small self-hosted “API” wrapper on top of eSIMAccess, letting you manage eSIMs with minimal friction. Feel free to expand by adding a front-end, or hooking these calls into Google Sheets or other workflows.

Happy coding—and safe travels! If you run into issues or want to explore advanced authentication or error handling, the official Apps Script documentation and eSIMAccess docs are great resources.

Discover more from eSIM Access

Subscribe now to keep reading and get access to the full archive.

Continue reading