Get Offers
The Get Offers API endpoint provides a way to retrieve a comprehensive list of available offers. Its primary purpose is to allow an application to display a browsable catalog of deals to the user. The endpoint is highly flexible, supporting advanced filtering by location, category, and tags, as well as robust sorting and pagination options to create a customized user experience.
Prerequisites
Before making an API call to get offers, ensure that the necessary user-level session token has been obtained. This token is required to authenticate API requests and can be acquired by following the User Client Level Authentication.
Steps to Implement
-
Construct the API Request
- Purpose: Allows a client to retrieve a set of tailored offers.
- Endpoint Reference: Get offers
- Usage: Make a
GET
request to the specified endpoint. The results can be tailored by appending various query parameters to the URL. For instance, you can add parameters for location (latitude
,longitude
), filtering (filter
), sorting (sort_by
), and pagination (limit
,offset
).
-
Process the Response
- Purpose: To handle the data returned by the API and display it within the application.
- Response Body: A successful (
200 OK
) response will contain a JSON object with a list of offers that match the query criteria. - Error Handling: Your application should be prepared to handle potential error responses, such as
400 Bad Request
if query parameters are invalid, or500 Internal Server Error
if the service fails to process the request. The error response body will contain anerror_code
and a user-friendlyerror_message
.
Key Considerations
- Pagination is Essential: Always use the
limit
andoffset
parameters to manage the number of returned results. Fetching an unbounded list of offers can lead to poor performance and long loading times. A typical implementation would fetch a set number of offers (e.g., 20) and use theoffset
to load more as the user scrolls. - Location-Based Searching: To search for offers within a specific geographic area, you must provide the
latitude
,longitude
, andradius
parameters together. Omitting any of these will result in the location filter failing. - Complex Filtering: The
filter
parameter is a powerful JSON object that allows for deep filtering based on multiple criteria. Ensure that the object structure is correctly formatted to avoid400 Bad Request
errors. - Sorting Options: The
sort_by
parameter allows results to be ordered by relevance, distance, or popularity. This can be used to surface the most relevant offers to the user first.
Example Workflow
Scenario: A user wants to find the most popular dining offers within a 10-kilometer radius of their current location.
- Get User Location: The application first obtains the user's current latitude and longitude from their device.
- Construct Request: The application builds and sends a GET request to the Kigo API.
- Endpoint: Get offers
- Query Parameters
latitude=44.9441
longitude=-93.0936
radius=10
search_radius_unit=kilometers
filter={"category": "dining"}
sort_by=[{"field": "most_popular_brands"}]
limit=25
offset=0
- Receive Response: The Kigo API returns a 200 OK status and a JSON response containing a list of up to 25 of the most popular dining offers matching the criteria.
- Display Results: The application parses the JSON response and displays the list of offers, including details like the merchant name, offer title, and savings.
- Load More: If the user scrolls to the end of the list, the application can make a new API call with an increased offset (e.g., offset=25) to fetch the next page of results.
Best Practices
- Implement Sensible Defaults: For a better user experience, set default values for parameters like limit and search_radius in your application.
- Validate User Input: Before making an API call, validate any user-provided input, such as coordinates, to ensure it is in a valid format.
- Use Specific Filters: Leverage the filter parameter to narrow down results on the server-side. Avoid fetching a large, unfiltered dataset and performing the filtering on the client, as this is inefficient.
- Cache Strategically: For general, non-personalized requests that are likely to be repeated, consider caching the results for a short duration to improve your application's responsiveness and reduce the number of API calls.
Updated 3 days ago