Offers

The following section provides details about the offers endpoint. This endpoint allows users to retrieve all offers associated with their account. The response will include comprehensive information about each offer, including related data such as notifications, client information, and contact details. This endpoint is useful for users who need an overview of all their active offers and their associated details.


GET/api/offers

Get all offers for a user

This endpoint retrieves all offers associated with the user identified by the user_id attached to the bearer token. The response includes all related data, which can encompass zero or many offers.

Parameters

  • No parameters are needed; the user_id is extracted from the bearer token.

Example response

{
  "data": [
    {
      "id": "1",
      "attributes": {
        "user_id": "10",
        "company_id": "20",
        "name": "Special Offer",
        "is_visible": true,
        "offer_status": "active",
        "is_manually_rejected": false,
        "offer_type": "discount",
        "language": "English",
        "offer_date": "2023-01-01",
        "offer_number": "OFF123",
        "email_subject": "Your Special Offer",
        "characteristic": "Limited Time",
        "total_price_once": "100.00",
        "total_price_repeat": "10.00",
        "is_allowed_to_navigate": true,
        "created_at": "2023-01-01T12:00:00Z",
        "updated_at": "2023-01-02T12:00:00Z",
        "url": "<https://api.example.com/offers/1>",
        "draft_url": "<https://api.example.com/offers/1/draft>"
      },
      "relationships": {
        "notification": {
          "user_id": "10",
          "offer_id": "1",
          "is_push_notification": true
        },
        "client": {
          "id": "30",
          "company_name": "Example Client",
          "website_url": "https://www.exampleclient.com",
          "email": "client@example.com",
          "logo": "https://storage.example.com/logos/client.png",
          "phone_number": "+1-234-567-890"
        },
        "contact": {
          "firstname": "John",
          "lastname": "Doe",
          "gender": "Male",
          "email": "john.doe@example.com",
          "phone_number": "+1-987-654-3210",
          "note": "Important client contact"
        }
      }
    }
    // More offer objects
  ]
}

Notes

  • The user_id is extracted from the bearer token, ensuring that the offers returned are associated with the authenticated user.
  • The response includes detailed information about each offer, along with related notifications, client, and contact information.
  • Ensure that the bearer token is valid and associated with your account to retrieve the correct offers.

GET/api/offers/{offer_id}

Get offer by id

This endpoint retrieves a single offer based on the provided offer ID. The request checks if the user_id attached to the bearer token matches the user_id associated with the offer.

Parameters

  • offer_id (string): The unique identifier of the offer being retrieved.

Example Response

{
  "id": "1",
  "attributes": {
    "user_id": "10",
    "company_id": "20",
    "name": "Special Offer",
    "is_visible": true,
    "offer_status": "active",
    "is_manually_rejected": false,
    "offer_type": "discount",
    "language": "English",
    "offer_date": "2023-01-01",
    "offer_number": "OFF123",
    "email_subject": "Your Special Offer",
    "characteristic": "Limited Time",
    "total_price_once": "100.00",
    "total_price_repeat": "10.00",
    "is_allowed_to_navigate": true,
    "created_at": "2023-01-01T12:00:00Z",
    "updated_at": "2023-01-02T12:00:00Z",
    "url": "https://api.example.com/offers/1",
    "draft_url": "https://api.example.com/offers/1/draft"
  },
  "relationships": {
    "notification": {
      "user_id": "10",
      "offer_id": "1",
      "is_push_notification": true
    },
    "client": {
      "id": "30",
      "company_name": "Example Client",
      "website_url": "https://www.exampleclient.com",
      "email": "client@example.com",
      "logo": "https://storage.example.com/logos/client.png",
      "phone_number": "+1-234-567-890"
    },
    "contact": {
      "firstname": "John",
      "lastname": "Doe",
      "gender": "Male",
      "email": "john.doe@example.com",
      "phone_number": "+1-987-654-3210",
      "note": "Important client contact"
    }
  }
}

Notes

  • The user_id attached to the bearer token must match the user_id associated with the offer.
  • Ensure that the offer_id provided in the request URL is valid and associated with your account.
  • Only a single offer will be returned based on the provided offer_id.

GET/api/offers/{offer_id}/notes

Get all notes for an offer

This endpoint retrieves all notes associated with a specific offer, identified by offer_id. The request ensures that the user_id attached to the bearer token matches the user_id associated with the offer.

Parameters

  • offer_id (string): The unique identifier of the offer for which the notes are being retrieved.

Example Response

{
  "data": [
    {
      "id": "1",
      "attributes": {
        "offer_id": "123",
        "created_by": "user@example.com",
        "is_push_notification": true,
        "type": "info",
        "message": "Initial offer created.",
        "is_deleted_app": false,
        "created_at": "2023-01-01T12:00:00Z",
        "updated_at": "2023-01-01T12:30:00Z"
      }
    },
    {
      "id": "2",
      "attributes": {
        "offer_id": "123",
        "created_by": "user@example.com",
        "is_push_notification": false,
        "type": "update",
        "message": "Offer details updated.",
        "is_deleted_app": false,
        "created_at": "2023-01-02T12:00:00Z",
        "updated_at": "2023-01-02T12:30:00Z"
      }
    }
    // More note objects
  ]
}

Notes

  • The user_id attached to the bearer token must match the user_id associated with the offer.
  • Ensure that the offer_id provided in the request URL is valid and associated with your account.
  • The response includes detailed information about each note, including the creator, type, and timestamps.
  • Only notes associated with the specified offer_id will be returned.

GET/api/offers/{offer_id}/send

Send offer

To ensure data integrity and security, we have implemented middleware that performs various validation checks before an offer can be sent. This middleware is executed before processing the API request and applies the following rules:

Validation Rules

  • If an offer has been soft deleted, it is no longer valid for processing and cannot be sent.
  • The offer can only be sent if the company_id of the offer matches the company_id of the authenticated user making the API request.
  • This prevents unauthorized access to offers belonging to other companies.
  • If an offer has already been accepted or rejected, it cannot be sent again. This ensures that status updates remain consistent and prevents duplicate processing of previously handled offers. If the send_date of the offer has passed, the offer is considered expired and cannot be sent.

This validation logic ensures that only valid and authorized offers can be processed, preventing errors, security risks, and inconsistent data. If you have any questions or need further clarification, please feel free to reach out. 🚀

Was this page helpful?