A TypeScript SDK for integrating Markko API with NextJS applications.
npm install @meetmarkko/markko-nextjs-sdk
Add the following environment variables to your NextJS project's .env.local
file:
MPE_VERSION=
MPE_ORIGIN=
MPE_API_BASE_PATH=
MPE_PASSWORD_KEY=
MPE_PASSWORD_SECRET=
MPE_CLIENT_CREDENTIAL_KEY=
MPE_CLIENT_CREDENTIAL_SECRET=
You should also set the
NODE_ENV
environment variable todevelopment
orproduction
depending on your environment. In development the SSL certificate is not verified.
For Next.js applications, it's recommended to use this SDK in the following ways:
- In Server Components (recommended)
- In Route Handlers (
app/api/**/route.ts
)
- In
getServerSideProps
- In API routes (
pages/api/*
)
Client-side usage should be limited to non-sensitive operations only. For sensitive operations, always use server-side API routes.
// app/vendors/page.tsx
import { MarkkoSDK } from "@meetmarkko/markko-nextjs-sdk";
export default async function VendorsPage() {
const sdk = new MarkkoSDK({
// config
});
const vendors = await sdk.vendors.list();
return <div>{/* Your JSX */}</div>;
}
// app/api/vendors/route.ts
import { MarkkoSDK } from "@meetmarkko/markko-nextjs-sdk";
export async function GET() {
const sdk = new MarkkoSDK({
// config
});
const data = await sdk.vendors.list();
return Response.json(data);
}
Creates a new address.
-
data
: Object containing the address data -
oauth
: The OAuth token data - Returns: Promise with the created address
- Throws: APIError if the request fails
Deletes an address.
-
id
: The ID of the address to delete -
oauth
: The OAuth token data - Returns: Promise with the deleted address data
Looks up addresses by postcode.
-
postcode
: The postcode to search for (spaces are automatically removed) -
oauth
: The OAuth token data - Returns: Promise with a list of matching addresses
Looks up addresses by search term.
-
search
: The search term to search for -
oauth
: The OAuth token data - Returns: Promise with a list of matching addresses
Gets a list of nearby models by postcode.
-
postcode
: The postcode to search from -
model
: The model type to search for -
radius
: Search radius in miles (default: 10) -
limit
: Maximum number of results (default: 10) -
relationships
: Related data to include (optional) -
oauth
: The OAuth token data - Returns: Promise with a list of nearby models
Sets an address as the default.
-
id
: The ID of the address to set as default -
oauth
: The OAuth token data - Returns: Promise with the updated address data
Updates an existing address.
-
id
: The ID of the address to update -
data
: Object containing the update data -
oauth
: The OAuth token data - Returns: Promise with the updated address
- Throws: APIError if the request fails
Fetches the active product attributes.
-
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Example parameters:
-
sort
: Sort order (e.g., 'created_at,desc') -
with
: Include related resources -
paginate
: Number of items per page -
page
: Page number -
is_active
: Filter by active status
Logs in a user.
-
data
: Object containing the login data - Returns: Promise with the API response
Logs out the current user.
-
oauth
: The OAuth token data - Returns: Promise with the API response
Request a password reset link for a user.
-
email
: The email address of the user - Returns: Promise with the API response
Update a user's password.
-
data
: Object containing the new password, password confirmation and the reset token (email, password, password_confirmation, token) - Returns: Promise with the API response
Fetches a list of blog posts.
-
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a list of blog categories. By default, returns only active categories.
-
params
: Optional object containing query parameters- Default includes
is_active: true
- Default includes
-
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a list of blog posts for a specific category.
-
categoryId
: The numeric ID of the category -
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a single blog post by ID.
-
id
: The numeric ID of the blog post -
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a single blog post by its slug.
-
slug
: The URL slug of the blog post -
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a blog category by its slug, including associated posts. By default, returns only active categories.
-
slug
: The URL slug of the category -
params
: Optional object containing query parameters- Default includes
is_active: true
- Default includes
-
oauth
: The OAuth token data - Returns: Promise with the API response
Adds a product to the cart.
-
productId
: A Parameter for unique id of product. -
params
: Additional parameters such as quantity, variantId, attributes, etc. -
oauth
: The OAuth token data (optional). - Returns: A promise with the updated cart data.
Applies a coupon code to the cart.
-
code
: A Parameter for unique coupen code for cart. -
groupId
: A parameter for cart's groupID . -
params
: Additional parameters such as cart_group_id, with, etc. -
oauth
: The OAuth token data (optional). - Returns: A promise with the updated cart data after applying the coupon.
Applies a promotion to the cart.
-
id
: A parameter for unique id for apply promotion. -
groupId
: A paramater for unique groupID of cart. -
params
: Additional parameters such as cart_group_id, with, etc. -
oauth
: The OAuth token data (optional). - Returns: A promise with the updated cart data after applying the promotion.
Deletes the user's cart.
-
oauth
: The OAuth token data (optional). - Returns: A promise with the response data after deleting the cart.
Shares the cart via email.
-
email
: The recipient's email address. -
oauth
: The OAuth token data (optional).
Returns: A promise with the response data after sharing the cart.
Retrieves a list of available promotions.
-
params
: Query parameters to filter promotions. -
oauth
: The OAuth token data (optional). - Returns: A promise with the list of promotions available on the platform.
Retrieves cart details using a shared code.
-
code
: The unique share code for the cart. -
params
: Additional query parameters for the request. -
oauth
: The OAuth token data (optional). - Returns: A promise with the cart details associated with the provided share code.
Updates the gift options for a cart.
-
groupId
: A paramater for unique groupId of cart. -
isGift
: A paramater for add gift option. -
params
: Additional parameters such as is_gift, gift_message, etc. -
oauth
: The OAuth token data (optional). - Returns: A promise with the updated cart details after applying the gift options.
Removes a product from the cart.
-
productId
: A Parameter for unique id of product. -
params
: Additional parameters such as variant_id, with, etc. -
oauth
: The OAuth token data (optional). - Returns: A promise with the updated cart details after removing the product.
Fetches the current user's cart details.
-
params
: Additional parameters for the request. -
oauth
: The OAuth token data (optional). - Returns: A promise with the cart details.
Fetches cart details by its ID.
-
id
: The cart ID to fetch. -
params
: Additional parameters for the request. -
oauth
: The OAuth token data (optional). - Returns: A promise with the cart details.
Generates a shareable code for the user's cart.
-
oauth
: The OAuth token data (optional). - Returns: A promise with the shared cart code.
Updates the quantity of a product in the cart.
-
productId
: A Parameter for unique id of product. -
params
: Additional parameters such as variant_id, quantity, etc. -
oauth
: The OAuth token data (optional). - Returns: A promise with the updated cart data.
Fetches a list of all categories.
-
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a nested list of all categories.
-
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a single category by its ID.
-
id
: The numeric ID of the category -
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a single category by its slug.
-
slug
: The URL slug of the category -
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a list of all charities.
-
params
: Optional query parameters to filter the list of charities. -
oauth
: The OAuth token data - Returns: A promise with the list of all charities.
Fetches the details of a specific charity by its unique ID.
-
id
: (Required) The unique ID of the charity to retrieve. -
params
: (Optional) An object containing additional query parameters for filtering or including related data. -
oauth
: The OAuth token data - Returns: A promise with the charity data.
Registers a new charity with the provided data.
-
data
: Object containing the charity registration data -
oauth
: The OAuth token data - Returns: Promise - Returns true if successful
- Throws: APIError if the request fails or returns an error
Fetches a single charity by their URL slug.
-
slug
: The URL slug of the charity -
params
: Optional object containing query parameters- Default includes
is_active: 1
- Default includes
-
oauth
: The OAuth token data - Returns: Promise with the API response
Check if a charity (store) name is available.
-
name
: The store name to check -
oauth
: The OAuth token data - Returns: Promise with a boolean indicating if the name is unique
Submit a contact form to the tenant.
-
data
: The contact form data -
oauth
: The OAuth token data - Returns: Promise with the contact form data
Submit a contact form to a vendor.
-
data
: The contact form data -
oauth
: The OAuth token data - Returns: Promise with the contact form data
Submit repairs form.
-
data
: The service form data -
oauth
: The OAuth token data - Returns: Promise with the service form data
Fetches a list of available currencies.
-
params
: Optional object containing query parameters (default:{ is_enabled: 1 }
) -
oauth
: The OAuth token data (default:null
) - Returns: Promise with the API response containing a list of currencies
Fetches a donation based on its number.
-
number
: The donation number to filter by. -
params
: Optional query parameters to filter the result. -
oauth
: The OAuth token data - Returns: A promise with the donation data matching the number.
Fetches a list of all donations.
-
params
: Optional query parameters to filter the list of donations. -
oauth
: The OAuth token data - Returns: A promise with the list of all donations.
Processes a donation for a specific charity.
-
id
: The ID of the charity to donate to. -
data
: An object containing the donation details, such as amount, donor information, etc. -
oauth
: The OAuth token data - Returns: A promise with the donation response data, including transaction status and details.
Fetches a list of all events.
-
params
: Optional query parameters to filter the list of events. -
oauth
: The OAuth token data - Returns: A promise with the list of all events.
Fetches a single event by its unique ID.
-
id
: The unique ID of the event to retrieve. -
params
: Optional query parameters to filter the event details. -
oauth
: The OAuth token data - Returns: A promise with the event data.
Saves an event with the provided data.
-
id
: The ID of the event to update. -
data
: An object containing the event data to be saved. -
oauth
: The OAuth token data - Returns: A promise with the saved event data.
Cancels an event.
-
id
: The ID of the event to cancel. -
data
: An object containing the event data to be saved. -
oauth
: The OAuth token data - Returns: A promise with the saved event data.
Get list of files.
-
oauth
: The OAuth token data - Returns: Promise with the API response
Get file by id.
-
id
: Id selector for fetching a file -
oauth
: The OAuth token data - Returns: Promise with the API response
Delete file by id.
-
id
: Id selector for deleting a file -
oauth
: The OAuth token data - Returns: Promise with the API response
Download file by id.
-
id
: Id selector for downloading a file -
oauth
: The OAuth token data - Returns: A url to download the file
Update a file.
-
payload
: The file payload containing the file id or model id and the model data -
oauth
: The OAuth token data - Returns: Promise with the API response
Register a file.
-
payload
: The file payload containing the S3 file response and the model data -
oauth
: The OAuth token data - Returns: Promise with the API response
Get list of images.
-
params
: Optional query parameters to filter the list of images -
oauth
: The OAuth token data - Returns: Promise with the API response
Get image by id.
-
id
: Id selector for fetching an image -
oauth
: The OAuth token data - Returns: Promise with the API response
Delete image by id.
-
id
: Id selector for deleting an image -
oauth
: The OAuth token data - Returns: Promise with the API response
Delete multiple images by ids.
-
imageIds
: Array of Ids selector for deleting images -
oauth
: The OAuth token data - Returns: Promise with the API response
Register an image.
-
payload
: The image payload containing the S3 image response and the model data -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a list of all messaging channels.
-
params
: Optional query parameters to filter the list of channels. -
oauth
: The OAuth token data - Returns: A promise with the list of all channels.
Fetches a single channel by its unique ID.
-
channelId
: The unique ID of the channel to retrieve. -
params
: Optional query parameters (includes pagination settings). -
oauth
: The OAuth token data - Returns: A promise with the channel data and messages.
Loads more messages for a specific channel.
-
channelId
: The ID of the channel to load messages from. -
params
: Pagination parameters (page, paginate). -
oauth
: The OAuth token data - Returns: A promise with the messages data.
Sends a new message.
-
params
: Object containing message data:-
order_id
: Optional order ID reference -
event_id
: Optional event ID reference -
is_update
: Boolean flag for update messages (required to be false ifchannel_name
is not provided) -
channel_name
: Optional name of the channel to send the message to (required ifis_update
is false) -
recipient_id
: The ID of the recipient (required) -
message
: Object containing the message details:-
body
: The content of the message (required) -
files
: Optional array of files to attach
-
-
meta
: Optional metadata related to the message
-
-
oauth
: The OAuth token data - Returns: A promise with the sent message data.
Closes a messaging channel.
-
channelId
: The ID of the channel to close. -
oauth
: The OAuth token data - Returns: A promise with the response data from closing the channel.
Get a list of authenticated user's booking orders.
-
params
: Optional object containing parameters to filter the response -
oauth
: The OAuth token data - Returns: Promise with the API response
Get an invoice by its ID.
-
id
: The ID of the invoice to download. -
oauth
: The OAuth token data. - Returns: A promise with the invoice data.
Fetches a single order by its ID.
-
id
: The numeric ID of the order -
oauth
: The OAuth token data - Returns: Promise with the API response
Get a single Order by order number.
-
params
: Optional object containing parameters to filter the response -
oauth
: The OAuth token data - Returns: Promise with the API response
Get a list of authenticated user's orders.
-
params
: Optional object containing parameters to filter the response -
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a list of all products.
-
params
: Optional query parameters to filter the list of products. -
oauth
: The OAuth token data - Returns: A promise with the list of all products.
Fetches a filtered list of products with advanced filtering options.
-
params
: The filter parameters for the products query (includes pagination support). -
oauth
: The OAuth token data - Returns: A promise with the filtered list of products.
Fetches a single product by vendor and product slug.
-
vendorSlug
: The slug of the vendor -
productSlug
: The slug of the product -
params
: Optional API parameters -
oauth
: The OAuth token data - Returns: A promise with the product data.
Fetches a single product by its unique ID.
-
id
: The unique ID of the product to retrieve -
params
: Optional API parameters -
oauth
: The OAuth token data - Returns: A promise with the product data.
Fetches a single product by its slug.
-
slug
: The slug of the product to retrieve -
params
: Optional API parameters -
oauth
: The OAuth token data - Returns: A promise with the product data.
Fetches the most recently added products.
-
count
: The number of products to retrieve (default = 3) -
params
: Optional API parameters -
oauth
: The OAuth token data - Returns: A promise with the list of latest products.
Looks up a product variant by code.
-
id
: Product ID -
code
: Variant code (e.g., '1.4-2.12-6.7') -
oauth
: The OAuth token data - Returns: A promise with the product variant data.
Retrieves the count of products.
-
params
: Optional query parameters. -
oauth
: The OAuth token data. - Returns: A promise with the product count.
Creates a new product.
-
product
: An object containing product details. -
oauth
: The OAuth token data. - Returns: A promise with the created product data.
Updates an existing product.
-
id
: The unique ID of the product to update. -
product
: An object containing updated product details. -
oauth
: The OAuth token data. - Returns: A promise with the updated product data.
Deletes a product by its unique ID.
-
id
: The unique ID of the product to delete. -
oauth
: The OAuth token data. - Returns: A promise confirming deletion.
Deletes multiple products by their IDs.
-
productIds
: An array of product IDs to delete. -
oauth
: The OAuth token data. - Returns: A promise confirming the deletion of multiple products.
Retrieves a list of variants for a specific product.
-
product
: The product object containing the product ID. -
oauth
: The OAuth token data. - Returns: A promise with a list of product variants.
Fetches the list of product options.
-
product
: The product object. -
oauth
: The OAuth token data. - Returns: A promise with the list of product options.
Lookup a reference value by category.
-
params
: Optional query parameters for filtering the reference values. -
oauth
: The OAuth token data (optional). - Returns: A promise resolving to an array of reference values.
Fetches a list of all reviews.
-
params
: Optional query parameters to filter the list of reviews. -
oauth
: The OAuth token data - Returns: A promise with the list of all reviews.
Creates a new review.
-
data
: Object containing the review data -
oauth
: The OAuth token data - Returns: A promise with the created review data.
Updates an existing review.
-
data
: Object containing the updated review data -
oauth
: The OAuth token data - Returns: A promise with the updated review data.
Deletes an existing review.
-
id
: The ID of the review to delete -
oauth
: The OAuth token data - Returns: A promise with the deleted review data.
The Specifications API provides endpoints for managing specifications, including fetching a list of specifications and retrieving specific specifications by their code.
Fetches a list of specifications.
-
params
: The query parameters for the request -
oauth
: The OAuth token data (optional) for authentication - Returns: Promise with the data from the response
Fetches a specific specification by code.
-
code
: The code of the specification to retrieve -
params
: The query parameters for the request -
oauth
: The OAuth token data (optional) for authentication - Returns: Promise with the data from the response
Fetches a list of all specification groups.
-
params
: Optional query parameters to filter the list of specification groups. -
oauth
: The OAuth token data - Returns: A promise with the list of all specification groups.
Fetches a specific specification group by ID.
-
id
: The ID of the specification group to retrieve. -
params
: Optional query parameters to filter the specification group. -
oauth
: The OAuth token data - Returns: A promise with the specification group data.
Fetches a list of all tags.
-
params
: Optional query parameters to filter the list of tags. -
oauth
: The OAuth token data - Returns: A promise with the list of all tags.
The Users API provides endpoints for managing user accounts, including user registration, profile management, email verification, and wishlist functionality.
Retrieves the currently authenticated user.
-
oauth
: The OAuth token data - Returns: Promise with the user data
create(data: { first_name: string; last_name: string; email: string; password: string; password_confirmation: string; terms: boolean; currency_id: string; phone?: string; }, oauth: TokenData | null = null)
Creates a new user.
-
data
: Object containing user registration data -
oauth
: The OAuth token data - Returns: Promise with success or failure message
- Throws: Error if the API call fails or validation fails
Deletes the currently authenticated user.
-
oauth
: The OAuth token data (optional) for authentication - Returns: Promise with the response data from the deletion operation
- Throws: Error if the API call fails
Checks if an email exists in the team.
-
email
: The email address to check -
oauth
: The OAuth token data (optional) - Returns: Promise with a boolean indicating if the email exists
updateProfile(data: { first_name: string; last_name: string; phone?: string; password?: string; password_confirmation?: string; currency_id: string; }, oauth: TokenData | null = null)
Updates the user's profile with the provided data.
-
data
: Object containing user profile data to update -
oauth
: The OAuth token data (optional) - Returns: Promise with the updated user data
- Throws: Error if the API call fails or if validation fails
Sends an email verification link to the user.
-
oauth
: The OAuth token data (optional) for authentication - Returns: Promise with the result of the operation, typically a success message
- Throws: Error if the API call fails
Retrieves the user's wishlist.
-
oauth
: The OAuth token data (optional) for authentication - Returns: Promise with the response data containing the user's wishlist items
Adds a product to the authenticated user's wishlist.
-
id
: The ID of the product to add to the wishlist -
oauth
: The OAuth token data (optional) for authentication - Returns: Promise with the updated wishlist
Removes a product from the authenticated user's wishlist.
-
id
: The ID of the product to remove from the wishlist -
oauth
: The OAuth token data (optional) for authentication - Returns: Promise with the response data indicating the result of the operation
Fetches a list of vendors based on the provided parameters.
-
params
: Optional object containing query parameters -
oauth
: The OAuth token data - Returns: Promise with the API response
Example parameters:
-
sort
: Sort order (e.g., 'created_at,desc') -
with
: Include related resources -
paginate
: Number of items per page -
page
: Page number -
is_approved
: Filter by approval status -
is_onboarded
: Filter by onboarding status -
is_rejected
: Filter by rejection status -
condensed
: Return condensed response
Fetches vendors filtered by postcode.
-
postcode
: The postcode to filter vendors by (spaces are automatically removed) -
params
: Optional object containing query parameters- Default includes
is_active: 1
- Default includes
-
oauth
: The OAuth token data - Returns: Promise with the API response
Fetches a single vendor by their URL slug.
-
slug
: The URL slug of the vendor -
params
: Optional object containing query parameters- Default includes
is_active: 1
- Default includes
-
oauth
: The OAuth token data - Returns: Promise with the API response
Follow a vendor.
-
id
: The numeric ID of the vendor to follow -
oauth
: The OAuth token data - Returns: Promise with the API response
Unfollow a vendor.
-
id
: The numeric ID of the vendor to unfollow -
oauth
: The OAuth token data - Returns: Promise with the API response
Check if a vendor (store) name is available.
-
name
: The store name to check -
oauth
: The OAuth token data - Returns: Promise with a boolean indicating if the name is unique
Registers a new vendor with the provided data.
-
data
: Object containing the vendor registration data -
oauth
: The OAuth token data - Returns: Promise - Returns true if successful
- Throws: APIError if the request fails or returns an error
Updates a vendor by its ID.
-
id
: The ID of the vendor to update -
data
: The vendor data to be updated -
oauth
: The OAuth token data - Returns: Promise with the API response
Deletes a vendor by its ID.
-
id
: The ID of the vendor to delete -
oauth
: The OAuth token data - Returns: Promise with the API response
The SDK automatically handles OAuth2 authentication using client credentials. It will:
- Automatically obtain access tokens when needed
- Cache tokens until they expire
- Refresh tokens before they expire
- Add the Bearer token to all API requests
You don't need to handle authentication manually, but you can access the token if needed:
const token = await sdk.getAccessToken();
ISC