Docs / Get started

Authentication

Every V1 call carries a project key in the Authorization header:

sh
curl https://hub.masjidbox.com/v1/masjids/msj_ap20t2m2tk \
  -H "Authorization: Bearer $MASJIDBOX_KEY"

A call without a key, or with a key that is malformed, unknown or revoked, answers 401 with the code INVALID_API_KEY. There are no test keys: every key reads the live data.

Secret or publishable

KeyWhere it livesIf it leaks
mbx_sk_live_… secretYour server onlyRevoke it at once
mbx_pk_live_… publishableA website, a mobile app, other code you shipAnyone who copies it can read the public API and this project's contribution totals, get referral links and submit suggestions credited to the project. It never changes a masjid's data, and its calls are rate-limited. Revoke it and ship a new one

Use a secret key whenever the call can go through your own server. Use a publishable key on a website, in a mobile app or in other code you ship, when the call comes from the user's device; anyone can read it there, so treat it as public.

From a browser

A website can call the API from its visitors' browsers with a publishable key. First add the site's origin to the key in the console, such as https://www.example.org: until then, the API refuses browser calls made with that key.

js
const res = await fetch('https://hub.masjidbox.com/v1/masjids/msj_ap20t2m2tk', {
  headers: { Authorization: 'Bearer mbx_pk_live_…' },
});
  • An origin is a scheme, a host and an optional port. List each site: https://example.org and https://www.example.org are two origins. A key accepts up to 10, and no wildcard.
  • For development, add http://localhost: it matches every port.
  • Allowed origins stop other websites from using your key in their visitors' browsers. They do not stop a script or an app, which can send any origin it likes: the key stays public, and its calls count against your project's quota and rate limit. Revoke it if someone else uses it.
  • A key without origins is an app key: calls without an Origin header (mobile apps, servers) work, browser calls are refused.
  • Never put a secret key in a web page: the page cannot read the answers, and anyone who opens the page can copy the key.

When the origin is not allowed, the API answers 403 with the code ORIGIN_NOT_ALLOWED. Your page can read that answer, so you can log it; the call does not count against the key's rate limit.

Projects and keys

A project is one app. Its keys share its quota, so a second key does not give you a second quota. Create one key per place that calls the API (a server, a website, an app), so you can revoke one without touching the others.

Keep a secret key secret

  • Read it from an environment variable or a secret manager, never from your source code.
  • We store only a hash of it: nobody, us included, can show it again. Lost it? Create a new one and revoke the old one.
  • If it leaks, revoke it from the console. A revoked key is refused within a minute, everywhere.