Skip to main content

HTTP API quickstart

Make your first calls to the Megido HTTP API in a few minutes, with curl, Python or JavaScript: start without a key, then get a key your user allows.

The API is at https://api.megido.io/v1. Each tool is POST /v1/tools/<tool> with its arguments as a JSON body, and its answer holds summary, data and meta. There is no SDK: the examples use curl, Python with requests (pip install requests), and JavaScript with fetch as an ES module (a .mjs file) in Node 18 or later. The examples on GitHub run the same steps as scripts.

1. Call without a key​

The index tools, search_cohorts, get_cohort, search_projects and get_project_card, work without a key or sign-in within a free quota of your network each calendar month; capabilities, usage and guide are free. See what is left of the quota with usage:

curl -X POST https://api.megido.io/v1/tools/usage

Then ask a market question: which niches a topic falls into, for a map of its players.

curl -X POST https://api.megido.io/v1/tools/search_cohorts \
-H "Content-Type: application/json" \
-d '{"text": "invoicing for freelancers", "limit": 3}'

Each niche in data comes with its cohort_id. Open one with get_cohort and "parts": ["distributions"] to see how its players spread by size, growth and country, without naming a site. Answers say in meta.notes when the free quota is about to run out; past it, a call is refused with quota_exhausted, and a key is the way on.

For more than the free quota of your network, ask your user for a key. Request a link and a code, with the name your user knows your app by:

curl -X POST https://api.megido.io/v1/keys/request \
-H "Content-Type: application/json" \
-d '{"client_name": "My research script"}'

The answer gives a link and a code for your user and a device_code for you. Show your user the link and the code: they sign in to Megido, or continue without registration, check that the code matches and allow the key. Meanwhile, ask for the key every interval seconds until it comes:

curl -X POST https://api.megido.io/v1/keys/token \
-H "Content-Type: application/json" \
-d '{"device_code": "<device_code>"}'

Until your user answers, the poll gives authorization_pending. The key comes once: keep it on your server, never in a web page. Niche and project ids found before you had the key do not work with it: search again. A registered account can also create keys itself in the Megido portal, under Keys and apps.

3. Call with your key​

Send the key in the Authorization header; the examples read it from the MEGIDO_API_KEY environment variable. A call that may charge takes estimate: true first: the estimate is free, says what the call will charge and returns a quote_token, which runs exactly what was estimated, for no more. Here the products closest to an idea, its competitors, anonymously: what each site does, its size and growth, without its domain.

curl -X POST https://api.megido.io/v1/tools/search_projects \
-H "Authorization: Bearer $MEGIDO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "invoicing for freelancers", "limit": 5, "estimate": true}'

curl -X POST https://api.megido.io/v1/tools/search_projects \
-H "Authorization: Bearer $MEGIDO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"quote_token": "<quote_token>"}'

Within the free quota the call charges nothing. Revealing a domain and buying parts of a site's profile are paid from your organization's credits: What costs what gives the prices.

When a call is refused​

A refusal charges nothing, and its message says what to do:

  • 401 with unauthorised: the key is wrong, revoked or expired, or the Authorization header holds no key.
  • 402 with quota_exhausted: the free quota does not cover the call; without a key, get one through a link.
  • 403 with sign_up_required: the tool is open to registered accounts; the refusal gives the page where your user registers.
  • 429 with rate_limited: too many calls; call again after Retry-After seconds.

Errors in the client guide lists every code.

Quoting and embedding​

Wherever you quote or show data from the API, give a link to https://megido.io. You may build Megido into a product for your own users: call the API for each request of a user and show that user the answer, without storing, accumulating or republishing domains or figures beyond it. These calls are paid from your organization's credits like any other. Section 5 of the Terms of Service sets these rules.

Next​

  • The API reference: every tool's arguments, answers and errors, and the OpenAPI document.
  • The HTTP API in the client guide: keys, estimates and retries, limits.
  • The Postman collection, with the same calls and a key through a link.

View as Markdown