API ReferenceGoals

POST Goal

Create a server-side custom goal event for a known visitor.

POST Goal

POST https://api.faurya.com/api/v1/goals

Create a custom goal event for a visitor. Requires Bearer Token authentication.

Request body

Send a JSON object with the following fields:

Required fields

  • faurya_visitor_id (string): Visitor ID from the Faurya browser cookie.
  • name (string): Goal name. The API records this as the event name.

Optional fields

  • faurya_session_id (string): Session ID from the browser cookie when available.
  • metadata (object): Extra primitive values to attach to the goal.

Metadata rules

  • metadata must be a JSON object.
  • Maximum 10 metadata attributes are allowed.
  • Values must be primitive values: string, number, boolean, null, or undefined.
  • Objects and arrays are rejected.

The visitor must already exist for the authenticated site before a goal can be recorded.

Response

  • 200 OK: Goal event created.
  • 400 Bad Request: Missing required fields or invalid metadata.
  • 401 Unauthorized: Missing or invalid API key.
  • 404 Not Found: Visitor or site not found.
  • 429 Too Many Requests: Account event limit reached.

Example request

const response = await fetch("https://api.faurya.com/api/v1/goals", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.FAURYA_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    faurya_visitor_id: req.cookies.faurya_visitor_id,
    faurya_session_id: req.cookies.faurya_session_id,
    name: "newsletter_signup",
    metadata: {
      plan: "pro",
      source: "pricing_page",
    },
  }),
});

const result = await response.json();

Success response

{
  "status": "success",
  "data": [
    {
      "message": "Custom event created successfully",
      "eventId": "67f8b9b5c320277df9a9d681"
    }
  ]
}