Forbrukermakt.no API beskrivelse

Forbrukermakt.no API Help Center

Use this guide to connect an external website to your petition so visitors can sign directly from your own site.

What the Petition API does

The Petition API lets you:

  • accept signatures from external websites

  • show live signature count on your own website

  • keep full control over access and visibility

Before you start

You need:

  1. A petition you own

  2. A personal API token with create permission

  3. The domain name(s) of the external website(s) that will send signatures

Step 1: Open petition settings

Go to:

Dashboard -> Create petition or Dashboard -> Edit petition

Open:

Advanced settings: API and visibility

In this section you can:

  • Enable API submissions

  • Add allowed domains (one per line)

  • Hide a petition from public pages

Step 2: Enable API submissions

Turn on:

Enable API submissions

This allows external websites to submit signatures through the API.

Step 3: Add allowed domains

In Allowed domains, add one hostname per line, for example:

example.com forms.example.org localhost 127.0.0.1:8000

Important:

  • use hostname only

  • port is optional (for local dev, e.g. 127.0.0.1:8000)

  • do not include https://

  • do not include /path

Requests from domains not in this list will be rejected.

Step 4: Create an API token

Go to:

Profile -> API Tokens

Direct path:

/user/api-tokens

Create a token with at least:

  • create permission

Store the token securely. It is shown only once.

Step 5: Submit signatures from your external website

Use this endpoint:

POST /api/v1/petitions/{petition-slug}/signatures

Required headers:

  • Authorization: Bearer YOUR_TOKEN

  • Origin: https://your-allowed-domain.example

  • Content-Type: application/json

Body example:

{ "full_name": "Jane Doe", "email": "jane@example.org", "accept_terms": true, "show_name_public": false, "comment": "I support this campaign." }

Success response:

  • 202 Accepted

Step 6: Show signature count on your website

Use this endpoint:

GET /api/v1/petitions/{petition-slug}/signature-count

This endpoint returns verified signatures only.

Email verification behavior

API signatures must still be verified by email.

That means:

  • signature is stored immediately

  • signer receives verification email

  • signature count increases only after verification

Visibility setting: hide from public pages

If you enable:

Hide this petition from public pages

Then the petition is removed from:

  • homepage petition lists

  • topic pages

  • search

  • sitemap

And direct public page access returns 404.

API submission and signature count can still work if API is enabled and domains are configured.

Common errors and fixes

403 domain_not_allowed

Cause: request domain does not match allowed domains.

Fix:

  • check Origin header in request

  • add correct hostname to allowed domains

403 missing_token_permission

Cause: token does not include create.

Fix:

  • create new token with create permission

403 api_disabled

Cause: API submissions are disabled for the petition.

Fix:

  • enable API submissions in petition settings

409 duplicate_signature

Cause: same email already signed this petition.

Fix:

  • do not submit duplicate emails for same petition

422 validation error

Cause: missing or invalid fields.

Fix:

  • send valid full_name, email, and accept_terms=true

Quick cURL examples

Submit signature:

curl -X POST "https://forbrukermakt.no/api/v1/petitions/my-petition/signatures" \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Origin: https://forms.example.org" \ -H "Content-Type: application/json" \ -d '{ "full_name":"Jane Doe", "email":"jane@example.org", "accept_terms":true }'

Get count:

curl "https://forbrukermakt.no/api/v1/petitions/my-petition/signature-count"

FAQ

Can I allow multiple websites?

Yes. Add each hostname on its own line.

Can I keep the petition private but still collect signatures via API?

Yes. Enable Hide this petition from public pages and keep Enable API submissions turned on.

Can external sites create petitions through API?

No. Current API supports signature submission and signature count only.

Why does the count not increase immediately?

Because signature count includes verified signatures only.