Customers

Customer

Overview by Shivang


GET Customer Details

  • Route: GET ../customers/{customerId}
  • Controller: CustomerController
  • Method: get
  • Request: Request
  • Description: Endpoint to retrieve details of a specific customer.

The get method in the CustomerController retrieves the details of a customer based on their ID. It first retrieves the customer using the customerService, ensuring a proper authorization check is performed to allow access to the customer's information. If authorized, it returns a CustomerResource containing the requested customer details.


Update Customer Details

  • Route: PATCH ../customers/{customerId}
  • Controller: CustomerController
  • Method: update
  • Request: UpdateCustomerRequest
  • Description: Endpoint to update details of a specific customer.

The update method in the CustomerController processes updates to a customer's information based on their ID. It first retrieves the customer using the customerService, ensuring a 404 error is thrown if the customer is not found. After verifying the authorization to update the customer, the method updates the customer’s details using the provided request data. Finally, it returns a CustomerResource containing the updated customer information.


Update Customer Password

  • Route: PUT ../customers/{customerId}/password
  • Controller: CustomerController
  • Method: updatePassword
  • Request: UpdatePasswordRequest
  • Description: Endpoint to update a customer's password.

The updatePassword method in the CustomerController allows a customer to update their password. It retrieves the customer using the customerService, ensuring proper authorization for the update. The method checks if the provided current password matches the stored password; if not, it returns a 422 Unprocessable Entity response with an error message. If the current password is correct, it hashes the new password and updates the customer's record. The method logs the password update event, removes any identity tokens, and returns a CustomerResource containing the updated customer information.


GET Customer Accounts

  • Route: GET ../customers/{customerId}/accounts
  • Controller: AccountController
  • Method: getAccountsForCustomer
  • Request: Request
  • Description: Endpoint to retrieve a list of accounts associated with a specific customer.

The getAccountsForCustomer method in the AccountController fetches the accounts linked to a customer identified by their ID. It starts by retrieving the customer using the customerService, ensuring a 404 error is thrown if the customer is not found. The method then checks for proper authorization to view the customer's accounts. It retrieves the accounts associated with the customer using the accountService, returning an AccountResource collection containing the customer's account information.


  • Route: GET ../customers/{customerId}/trolleys
  • Controller: TrolleyController
  • Method: getCustomerTrolleys
  • Request: ViewCustomerTrolleysRequest
  • Description: Endpoint to retrieve a list of trolleys associated with a specific customer.

The getCustomerTrolleys method in the TrolleyController fetches the trolleys linked to a customer identified by their ID. It uses the trolleyService to retrieve the trolleys associated with the customer. The method logs the trolley fetch event, including the customer ID and the retrieved trolley IDs, for debugging purposes. Finally, it returns a TrolleyResource collection containing the customer's trolleys.

Request Parameters for :

  • Header :- X-Toolstation-Customer-ID:- Token

Response:-

Status: 200 OK


"data": { "id": "01XXXXXXXXXXXX",
"customer_id": "XXXXXX9879",
"session_id": "819b12aXXXXXXXX",
"status": 1,
"name": null,
"created_at": "2024-08-08T13:37:39+02:00",
"updated_at": "2024-08-08T13:37:39+02:00",
"lines": [
{
"id": 128XXX,
"product_code": "6XXXX",
"quantity": 1,
"channel": 1,
"product_channel": 0,
"delivery_method_code": "0XXXX",
"created_at": "2024-08-08T13:37:40+02:00",
"updated_at": "2024-08-08T13:37:41+02:00"
}
],
"attributes": [],
"applied_promo_codes": [],
"order_id": null,
"ordered_at": null
},
// more data
  


GET Customer Active Trolleys

  • Route: GET ../customers/{customerId}/trolleys/active
  • Controller: TrolleyController
  • Method: getCustomerActiveTrolleys
  • Request: ViewCustomerTrolleysRequest
  • Description: Endpoint to retrieve a list of active trolleys associated with a specific customer.

The getCustomerActiveTrolleys method in the TrolleyController retrieves the active trolleys for a customer identified by their ID. It uses the trolleyService to fetch the active trolleys linked to the customer. The method logs the retrieval of active trolleys, including the customer ID and the corresponding trolley IDs, for debugging purposes. Finally, it returns a TrolleyResource collection containing the customer's active trolleys.


Create New Customer Trolley

  • Route: POST ../customers/{customerId}/trolleys
  • Controller: TrolleyController
  • Method: createNewCustomerTrolley
  • Request: CreateNewTrolleyRequest
  • Description: Endpoint to create a new trolley for a specific customer.

The createNewCustomerTrolley method in the TrolleyController handles the creation of a new trolley for a customer identified by their ID. If the customer ID is not "guest," it retrieves the customer to ensure they exist. The method then creates a new trolley using the trolleyService, associating it with the customer or marking it as a guest if applicable. It logs the creation event, including the customer ID, trolley ID, session ID, and trolley name. Finally, it returns a TrolleyResource with the created trolley and a 201 Created response.


Update Customer Contact Preferences

  • Route: PUT ../customers/{customerId}/contact-preferences
  • Controller: CustomerController
  • Method: updateContactPreferences
  • Request: UpdateContactPreferencesRequest
  • Description: Endpoint to update a customer's contact preferences.

The updateContactPreferences method in the CustomerController processes updates to a customer's contact preferences based on their ID. It first retrieves the customer using the customerService, ensuring a 404 error is thrown if the customer is not found. The method then verifies authorization to update the customer's preferences. It attempts to update the customer's details with the provided request data, logging an error if the customer cannot be found due to potential replication lag. Finally, it returns a CustomerResource containing the updated customer information.


Create Customer Catalogue Request

  • Route: POST ../customers/{customerId}/catalogue-requests
  • Controller: CatalogueRequestController
  • Method: store
  • Request: CustomerCatalogueRequest
  • Description: Endpoint to create a catalogue request for a specific customer.

The store method in the CatalogueRequestController handles the creation of a catalogue request for a customer identified by their ID. It retrieves the customer using the customerService, ensuring that a 404 error is thrown if the customer is not found. The method checks for authorization to view the customer. It then attempts to create a catalogue request using the provided address ID and the current date. If successful, it logs the request details. In case of an error, such as a CustomerModuleException, it logs a warning with the error message and returns a 422 Unprocessable Entity response. Finally, if the request is successful, it returns a 204 No Content response.


GET Last Customer Catalogue Request

  • Route: GET ../customers/{customerId}/last-catalogue-request
  • Controller: CatalogueRequestController
  • Method: lastRequest
  • Request: Request
  • Description: Endpoint to retrieve the date of the last catalogue request for a specific customer.

The lastRequest method in the CatalogueRequestController fetches the last catalogue request date for a customer identified by their ID. It starts by retrieving the customer using the customerService, ensuring a 404 error is thrown if the customer is not found. The method then checks for authorization to view the customer's information. It retrieves the date of the customer's last catalogue request and returns it as a JSON response, formatted to include the date as a string.


Request Customer Card

  • Route: PUT ../customers/{customerId}/card-request
  • Controller: CustomerCardController
  • Method: request
  • Request: CustomerCardRequest
  • Description: Endpoint to request a new card for a specific customer.

The request method in the CustomerCardController manages card requests for a customer identified by their ID. It starts by logging the type of card request. The customer is retrieved using the customerService, ensuring that a 404 error is thrown if the customer does not exist. The method checks for authorization to update the customer's card requests. It then looks for any incomplete card requests associated with the customer. If such requests exist, it logs the information and returns a 204 No Content response. If there are no incomplete requests, the method disables any existing trade credit cards for the customer, logs the action of creating a new card request, and proceeds to create the new customer card request using the provided type. Finally, it returns a 204 No Content response.


Set Default Branch

  • Route: PUT ../customers/{customerId}/default-branch
  • Controller: AssociatedBranchesController
  • Method: setDefaultBranch
  • Request: SetDefaultBranchRequest
  • Description: Endpoint to set a default branch for a specific customer.

The setDefaultBranch method in the AssociatedBranchesController updates the default branch for a customer based on their ID. It first retrieves the customer using the customerService and checks if the user is authorized to update the customer's information. If authorized, it updates the default branch using the provided site_id and returns a JSON response containing the updated default branch details. Debug logs are recorded for monitoring purposes.


Check Username Availability

  • Route: POST ../customers/username-check
  • Controller: CustomerUsernameCheckController
  • Method: __invoke
  • Request: CustomerUsernameCheckRequest
  • Description: Endpoint to check if a username (email) already exists for a customer.

The __invoke method in the CustomerUsernameCheckController checks if a customer exists with the provided username (email). It uses the CustomerUsernameCheckRequest for validation, ensuring the username is required and in a valid email format. The method retrieves the customer using the customerService and returns a JSON response indicating whether the username exists. Debug logs are recorded for monitoring purposes.


Request Account Deletion

  • Route: POST ../customers/{customerId}/request-account-deletion
  • Controller: CustomerController
  • Method: sendAccountDeletionRequest
  • Request: Request
  • Description: Endpoint to initiate the account deletion process for a specific customer.

The sendAccountDeletionRequest method in the CustomerController allows a customer to request account deletion. It first retrieves the customer using the customerService, ensuring that a 404 error is thrown if the customer is not found. The method then checks if the user is authorized to perform the action. If authorized, it logs the action and calls the service to send an account deletion request email to the customer. A response with a 204 No Content status is returned upon successful execution.


Register Trade Interest

  • Route: POST ../customers/{customerId}/register-trade-interest
  • Controller: CustomerController
  • Method: registerTradeInterest
  • Request: CustomerRegisterTradeInterestRequest
  • Description: Endpoint to register a customer's interest in a trade.

The registerTradeInterest method in the CustomerController allows a customer to express their interest in a trade. It retrieves the customer using the customerService, throwing a 404 error if the customer is not found. The method checks if the user is authorized to perform the action. If authorized, it calls the registerTradeInterest service method with the provided customerId and an optional force_send parameter (defaulting to false). A JSON response with a success message and a 200 status code is returned upon successful execution.


Generate One-Time QR Code

  • Route: POST ../customers/{customerId}/one-time-qrcode
  • Controller: CustomerController
  • Method: generateOneTimeQrCode
  • Request: Request
  • Description: Endpoint to generate a one-time QR code for a specific customer.

The generateOneTimeQrCode method in the CustomerController allows the generation of a one-time QR code for a customer. It retrieves the customer using the customerService, ensuring that the user is authorized to update the customer. Upon authorization, it calls the service method to generate the QR code. After generating the QR code, the customer instance is refreshed to reflect the updated data. The method returns a CustomerResource containing the updated customer information.


Update Loyalty Club Status

  • Route: PUT ../customers/{customerId}/loyalty-club
  • Controller: CustomerLoyaltyClubController
  • Method: __invoke
  • Request: Request
  • Description: Endpoint to enable or disable a customer's loyalty club account.

The __invoke method in the CustomerLoyaltyClubController updates the loyalty club status for a specified customer. It retrieves the customer using the customerService, ensuring that the user is authorized to perform the update. The method logs the action, including the customer ID and the desired status (enabled or disabled). Based on the enabled input from the request, it either enables or disables the customer's loyalty account. A response with a 204 No Content status is returned upon successful execution, indicating the operation was successful without any content to return.


GET Rewards Platform SSO URL

  • Route: GET /{customerId}/loyalty-club/rewards-platform-sso-url
  • Controller: CustomerLoyaltyClubController
  • Method: getRewardsPlatformSsoUrl
  • Request: Request
  • Description: Endpoint to retrieve the SSO URL for the rewards platform for a loyalty club member.

The getRewardsPlatformSsoUrl method in the CustomerLoyaltyClubController retrieves the single sign-on (SSO) URL for a customer who is a member of the loyalty club. It first logs the request, including the customer ID. The method retrieves the customer using the customerService and checks for authorization to access the customer's information. If the customer is not a loyalty club member, a 404 Not Found response is returned with a relevant message. If the customer is eligible, the method generates the SSO URL using the mlpService and returns it in a JSON response.

=================================================================================

Overview by Atul


title: Customer Route

Introduction

This Page provides an overview of the routes defined for the Customer purpose endpoints in the Toolstation E-Comm Api.

List of Routes for Customer

  1. /customers/_ping
  2. /customers/{customerId}
  3. /customers/{customerId}/orders
  4. /customers/{customerId}/purchase-history
  5. /customers/{customerId}/password
  6. /customers/{customerId}/accounts
  7. /customers/{customerId}/trolleys
  8. /customers/{customerId}/trolleys/active
  9. /customers/{customerId}/contact-preferences
  10. /customers/{customerId}/catalogue-requests
  11. /customers/{customerId}/last-catalogue-request
  12. /customers/{customerId}/saved-lists
  13. /customers/{customerId}/card-request
  14. /customers/{customerId}/favourite-branches
  15. /customers/{customerId}/favourite-branches/{siteId}
  16. /customers/{customerId}/default-branch
  17. /customers/username-check
  18. /customers/request-account-deletion
  19. /customers/{customerId}/register-trade-interest
  20. /customers/{customerId}/one-time-qrcode
  21. /customers/{customerId}/loyalty-club
  22. /customers/{customerId}/loyalty-club/rewards-platform-sso-url

GET: customers/_ping

  • Method: GET
  • Controller: PingController
  • Description: Endpoint to check if the authentication is valid and running successfully.

Response

Response Code: 200 OK

Response:

{
    "data": {
        "msg": "OK"
    }
}

GET: customers/{customerId}

  • Controller: CustomerController
  • Method: GET
  • Request: Request
  • Parameters:
    • customerId: Specifies the ID for retrieve specific customer.
  • Description: Endpoint for getting details of Customer.

The get function retrieves a specific customer by their ID using the CustomerService, ensures the current user is authorized to view the customer details, and then returns a CustomerResource that encapsulates the customer's data.

public function get(Request $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}:

  • Header :- Accept-Language:- en-UK,en

Response

Response Code: 200 OK

Response:

{
    "data": {
        "id": "CWW02XXXX",
        "title": "Mr",
        "first_name": "kulchandraa",
        "last_name": "kandel",
        "username": "XX@gmail.com",
        "email": "XX@gmail.com",
        "telephone": "",
        "mobile": "93155XXXX",
        "card_number": "",
        "company": "XXXXX",
        "vat_number": null,
        "account_type": null,
        "account_number": null,
        "loyalty_club_member": false,
        "loyalty_club_member_since": null,
        "credit_limit": null,
        "remaining_balance": null,
        "primary_address": {
            "id": "DXX0271XXXX",
            "type": 1,
            "line_1": "address1",
            "line_2": "address2",
            "line_3": "address3",
            "town": "DELHI",
            "county": "",
            "postcode": "110037",
            "country_id": 1,
            "formatted": [
                "address1",
                "address2",
                "address3",
                "DELHI",
                "110037",
                "United Kingdom"
            ]
        },
        "contact_preferences": {
            "mail_catalogues": false,
            "order_query": {
                "email": false,
                "telephone": false,
                "mobile": false,
                "sms": false,
                "push": false
            },
            "order_progress": {
                "email": false,
                "sms": false,
                "push": false
            },
            "offers_info": {
                "post": false,
                "email": false,
                "mobile": false,
                "sms": false,
                "push": false,
                "promo_centre": true
            }
        },
        "default_branch": "h1",
        "favourite_branches": [
            "h1"
        ],
        "spend_stats": {
            "last_month_spend": "0.00",
            "this_month_spend": "0.00",
            "estimated_savings_last_month": "0.00",
            "estimated_savings_this_month": "0.00",
            "spend_requirements": null
        },
        "token": "Token Code",
        "one_time_qr_code": null,
        "one_time_qr_code_base64": null
    }
}

Response Code: 404 Not Found

Response:

{
    "error": {
        "code": "404.99",
        "message": "Resource Not Found",
        "info": "https://developers.example.com",
        "data": null
    }
}

PATCH: customers/{customerId}

  • Controller: CustomerController
  • Method: PATCH
  • Request: UpdateCustomerRequest
    • Parameters:
    • customerId: Specifies the ID for update specific customer.
  • Description: Endpoint for updating details of Customer.

The update function retrieves a specific customer by ID, checks if the current user is authorized to update the customer, performs the update with the provided data, and returns the updated customer information encapsulated in a CustomerResource.

public function update(UpdateCustomerRequest $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer
  • Body:-
    • Example:-
      first_name: Xtoah LLPP,
      last_name: Singh,
      telephone: 9315XXXXX

Response

Response Code: 200 OK

Response:

{
    "data": {
        "id": "CWW0206XXXX",
        "title": "Mr",
        "first_name": "Xtoah LLPP",
        "last_name": "Singh",
        "username": "XX@gmail.com",
        "email": "XX@gmail.com",
        "telephone": "",
        "mobile": "9315582XXX",
        "card_number": "",
        "company": "XXXXXX",
        "vat_number": null,
        "account_type": null,
        "account_number": null,
        "loyalty_club_member": false,
        "loyalty_club_member_since": null,
        "credit_limit": null,
        "remaining_balance": null,
        "primary_address": {
            "id": "DXX02715XXXX",
            "type": 1,
            "line_1": "address1",
            "line_2": "address2",
            "line_3": "address3",
            "town": "DELHI",
            "county": "",
            "postcode": "110037",
            "country_id": 1,
            "formatted": [
                "address1",
                "address2",
                "address3",
                "DELHI",
                "110037",
                "United Kingdom"
            ]
        },
        "contact_preferences": {
            "mail_catalogues": false,
            "order_query": {
                "email": false,
                "telephone": false,
                "mobile": false,
                "sms": false,
                "push": false
            },
            "order_progress": {
                "email": false,
                "sms": false,
                "push": false
            },
            "offers_info": {
                "post": false,
                "email": false,
                "mobile": false,
                "sms": false,
                "push": false,
                "promo_centre": true
            }
        },
        "default_branch": "h1",
        "favourite_branches": [
            "h1"
        ],
        "spend_stats": {
            "last_month_spend": "0.00",
            "this_month_spend": "0.00",
            "estimated_savings_last_month": "0.00",
            "estimated_savings_this_month": "0.00",
            "spend_requirements": null
        },
        "token": "Token Code",
        "one_time_qr_code": null,
        "one_time_qr_code_base64": null
    }
}

Response Code: 403 Forbidden

Response:

{
    "error": {
        "code": "403.99",
        "message": "Forbidden",
        "info": "https://developers.example.com",
        "data": null
    }
}

Put: customers/{customerId}/password

  • Controller: CustomerController
  • Method: Put
  • Request: UpdatePasswordRequest
  • Parameters:
    • customerId: Identifies the specific customer whose password is being updated.
  • Description: Endpoint for updated the password.

The updatePassword function updates a customer's password by first validating the current password, then setting the new password, and finally removing any existing identity tokens for security, with parameters used to retrieve password data from the request and identify the customer.

public function updatePassword(UpdatePasswordRequest $request, $customerId)
{
    // Function implementation goes here
}

GET: customers/{customerId}/accounts

  • Controller: AccountController
  • Method: GET
  • Request: Request
  • Parameters:
    • customerId: Identifies the customer whose accounts are being retrieved.
  • Description: Endpoint for retrieve the list of accounts.

The getAccountsForCustomer function fetches and returns the accounts associated with a specified customer, first validating the customer’s existence and permissions, then retrieving the accounts with detailed attributes and returning them as a standardized collection.

public function getAccountsForCustomer(Request $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}/accounts:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer

Response

Response Code: 200 OK

Response:

{
    "data": []
}

Response Code: 403 Forbidden

Response:

{
    "error": {
        "code": "403.99",
        "message": "Forbidden",
        "info": "https://developers.example.com",
        "data": null
    }
}

Put: customers/{customerId}/contact-preferences

  • Controller: CustomerController
  • Method: Put
  • Request: UpdateContactPreferencesRequest
  • Parameters:
    • customerId: Identifies the customer whose contact preferences are being updated.
  • Description: Endpoint for update the contact preferences.

The updateContactPreferences function performs a critical role in managing customer data updates. It ensures that only authorized users can make changes, handles potential errors gracefully, and provides clear, structured responses. This function exemplifies a well-structured approach to updating resources in a web application, ensuring both security and reliability.

public function updateContactPreferences(UpdateContactPreferencesRequest $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}/contact-preferences:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer

Response

Response Code: 200 OK

Response:

{
    "data": {
        "id": "CWW0206XXXX",
        "title": "Mr",
        "first_name": "Xtoah LLPP",
        "last_name": "Singh",
        "username": "XX@gmail.com",
        "email": "XX@gmail.com",
        "telephone": "",
        "mobile": "9315582XXX",
        "card_number": "",
        "company": "XXXXXX",
        "vat_number": null,
        "account_type": null,
        "account_number": null,
        "loyalty_club_member": false,
        "loyalty_club_member_since": null,
        "credit_limit": null,
        "remaining_balance": null,
        "primary_address": {
            "id": "DXX02715XXXX",
            "type": 1,
            "line_1": "address1",
            "line_2": "address2",
            "line_3": "address3",
            "town": "DELHI",
            "county": "",
            "postcode": "110037",
            "country_id": 1,
            "formatted": [
                "address1",
                "address2",
                "address3",
                "DELHI",
                "110037",
                "United Kingdom"
            ]
        },
        "contact_preferences": {
            "mail_catalogues": false,
            "order_query": {
                "email": false,
                "telephone": false,
                "mobile": false,
                "sms": false,
                "push": false
            },
            "order_progress": {
                "email": false,
                "sms": false,
                "push": false
            },
            "offers_info": {
                "post": false,
                "email": false,
                "mobile": false,
                "sms": false,
                "push": false,
                "promo_centre": true
            }
        },
        "default_branch": "h1",
        "favourite_branches": [
            "h1"
        ],
        "spend_stats": {
            "last_month_spend": "0.00",
            "this_month_spend": "0.00",
            "estimated_savings_last_month": "0.00",
            "estimated_savings_this_month": "0.00",
            "spend_requirements": null
        },
        "token": "Token Code",
        "one_time_qr_code": null,
        "one_time_qr_code_base64": null
    }
}

Response Code: 403 Forbidden

Response:

{
    "error": {
        "code": "403.99",
        "message": "Forbidden",
        "info": "https://developers.example.com",
        "data": null
    }
}

POST: customers/{customerId}/catalogue-requests

  • Controller: CatalogueRequestController
  • Method: POST
  • Request: CustomerCatalogueRequest
  • Parameters:
    • customerId: Retrieve and associate the catalogue request with the appropriate customer.
  • Description: Endpoint to create catalogue request for an existing customer.

The store function is designed to handle requests for creating a new customer catalogue request. It involves validating and processing the request, interacting with services to fetch customer details, checking authorization, creating the catalogue request, logging relevant information, and handling potential errors. The function ensures that only authorized users can create catalogue requests for existing customers and provides appropriate feedback in case of success or failure.

public function store(CustomerCatalogueRequest $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}/catalogue-requests:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer

Response

Response Code: 200 OK

Response:

{
    "data": {
        "id": "CWW0206XXXX",
        "title": "Mr",
        "first_name": "Xtoah LLPP",
        "last_name": "Singh",
        "username": "XX@gmail.com",
        "email": "XX@gmail.com",
        "telephone": "",
        "mobile": "9315582XXX",
        "card_number": "",
        "company": "XXXXXX",
        "vat_number": null,
        "account_type": null,
        "account_number": null,
        "loyalty_club_member": false,
        "loyalty_club_member_since": null,
        "credit_limit": null,
        "remaining_balance": null,
        "primary_address": {
            "id": "DXX02715XXXX",
            "type": 1,
            "line_1": "address1",
            "line_2": "address2",
            "line_3": "address3",
            "town": "DELHI",
            "county": "",
            "postcode": "110037",
            "country_id": 1,
            "formatted": [
                "address1",
                "address2",
                "address3",
                "DELHI",
                "110037",
                "United Kingdom"
            ]
        },
        "contact_preferences": {
            "mail_catalogues": false,
            "order_query": {
                "email": false,
                "telephone": false,
                "mobile": false,
                "sms": false,
                "push": false
            },
            "order_progress": {
                "email": false,
                "sms": false,
                "push": false
            },
            "offers_info": {
                "post": false,
                "email": false,
                "mobile": false,
                "sms": false,
                "push": false,
                "promo_centre": true
            }
        },
        "default_branch": "h1",
        "favourite_branches": [
            "h1"
        ],
        "spend_stats": {
            "last_month_spend": "0.00",
            "this_month_spend": "0.00",
            "estimated_savings_last_month": "0.00",
            "estimated_savings_this_month": "0.00",
            "spend_requirements": null
        },
        "token": "Token Code",
        "one_time_qr_code": null,
        "one_time_qr_code_base64": null
    }
}

Response Code: 403 Forbidden

Response:

{
    "error": {
        "code": "403.99",
        "message": "Forbidden",
        "info": "https://developers.example.com",
        "data": null
    }
}

GET: customers/{customerId}/last-catalogue-request

  • Controller: CatalogueRequestController
  • Method: GET
  • Request: CustomerCatalogueRequest
  • Parameters:
    • customerId: Identify and retrieve a specific customer’s details and data, such as the date of their last catalog request.
  • Description: Endpoint to provides the date that the customer last requested a catalogue.

The lastRequest function retrieves the date of the last catalog request made by a specified customer, first ensuring the customer exists and that the current user is authorized to view the customer’s information, then returning the date as a JSON response formatted as a string.

public function lastRequest(CustomerCatalogueRequest $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}/last-catalogue-requests:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer

Response

Response Code: 200 OK

Response:

{
    "data": {
        "date": null
    }
}

Response Code: 404 Bad Request

Response:


<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>400 Bad Request</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Bad Request</h1>
<h2>Your client has issued a malformed or illegal request.</h2>
<h2></h2>
</body></html>

Put: customers/{customerId}/card-request

  • Controller: CustomerCardController
  • Method: Put
  • Request: CustomerCardRequest
  • Parameters:
    • customerId: Identify and create a new customer card request.
  • Description: Endpoint to manage and create new customer card requests.

The request function handles the creation of a customer card request by performing several key actions: logging request details, retrieving and authorizing the customer, checking for and managing existing incomplete requests, disabling old trade credit cards, creating a new card request, and returning a response to indicate the success of the operation. The function is designed to ensure proper authorization, prevent duplicate requests, and maintain accurate records of card requests and customer interactions.

public function request(CustomerCardRequest $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}/card-request:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer

Response

Response Code: 403 Forbidden

Response:


<!doctype html>
<meta charset="utf-8">
<meta name=viewport content="width=device-width, initial-scale=1">
<title>403</title>403 Forbidden

DELETE: customers/{customerId}/default-branch

  • Controller: AssociatedBranchesController
  • Method: DELETE
  • Request: Request
  • Parameters:
    • customerId: Identify the customer for whom the default branch is being set.
  • Description: Endpoint to set default branch.

The setDefaultBranch function sets the default branch for a customer and returns the newly set branch in a JSON response. It also logs debug messages for auditing purposes and checks for authorization before making changes.

public function setDefaultBranch(SetDefaultBranchRequest $request, $customerId): \Illuminate\Http\JsonResponse
{
    // Function implementation goes here
}

Request Parameters for customers/{customerId}/default-branch:

  • Header :- Accept-Language:- en-UK,en,
  • x-toolstation-customer-id:- Token Id of the customer

Response

Response Code: 403 Forbidden

Response:


<!doctype html>
<meta charset="utf-8">
<meta name=viewport content="width=device-width, initial-scale=1">
<title>403</title>403 Forbidden

POST: customers/username-check

  • Controller: CustomerUsernameCheckController
  • Method: POST
  • Request: CustomerUsernameCheckRequest
  • Description: Endpoint to check if username exists.

The __invoke function is an invokable method. It checks if a customer with a given username exists in the database. It takes a CustomerUsernameCheckRequest object as a parameter, validates the incoming request data, logs a debug message, retrieves the customer from the database using a customerService object, and returns a JSON response indicating whether the customer exists or not.

public function __invoke(CustomerUsernameCheckRequest $request)
{
    // Function implementation goes here
}

Request Parameters for /customers/username-check:

  • Header :- Accept-Language:- en-UK,en
  • username: Customer’s email address (string, required).

Response

Response Code: 200 OK

Response:

{
    "data": {
        "exists": true
    }
}
  • Error Response:-
    Status: 200 OK
    
      {
      "data": {
          "exists": false
      }
    
    }
    

POST: customers/{customerId}/request-account-deletion

  • Controller: CustomerController
  • Method: POST
  • Request: Request
  • Parameters:
    • customerId: Identify the customer for whom the account deletion request is being sent.
  • Description: Endpoint to request account deletion.

The sendAccountDeletionRequest function is responsible for sending an account deletion request email to a customer and handling the necessary authorization and logging.

public function sendAccountDeletionRequest(Request $request, $customerId)
{
    // Function implementation goes here
}

Request Parameters for /customers/{customerId}/request-account-deletion:

  • Header :- Accept-Language:- en-UK,en
  • username: Customer’s email address (string, required).

Response

Response Code: 204 No Content

  • Error Response:-
    Status: 200 OK
    
      {
      "data": {
          "exists": false
      }
    
    }
    

POST: customers/{customerId}/register-trade-interest

  • Controller: CustomerController
  • Method: POST
  • Request: CustomerRegisterTradeInterestRequest
  • Parameters:
    • customerId: Identify the customer for whom the trade interest is being registered.
  • Description: Endpoint to register customer interest and send an email.

This function registers a trade interest for a customer by calling the registerTradeInterest method of the customerService and returns a success message in JSON format.

public function registerTradeInterest(CustomerRegisterTradeInterestRequest $request, $customerId): 
{
    // Function implementation goes here
}

POST: customers/{customerId}/one-time-qrcode

  • Controller: CustomerController
  • Method: POST
  • Request: Request
  • Parameters:
    • customerId: Identify the customer for whom the one-time QR code is being generated.
  • Description: Endpoint to generate one-time QR code.

The generateOneTimeQrCode function generates a one-time QR code for a specific customer and returns the updated customer data as a resource. The function ensures that the request is authorized and uses a service to perform the QR code generation.

public function generateOneTimeQrCode(Request $request, $customerId)
{
    // Function implementation goes here
}

Put: customers/{customerId}/loyalty-club

  • Controller: CustomerLoyaltyClubController
  • Method: Put
  • Request: Request
  • Parameters:
    • customerId: Identify the customer for whom the loyalty account is being enabled or disabled.
  • Description: Endpoint to enable or disable a loyalty account.

The __invoke function handles a request to enable or disable a loyalty account for a customer based on the value of the 'enabled' input field in the request. It performs authorization checks, retrieves customer information, and updates the loyalty account accordingly.

public function __invoke(Request $request, string $customerId)
{
    // Function implementation goes here
}

GET: customers/{customerId}/loyalty-club/rewards-platform-sso-url

  • Controller: CustomerLoyaltyClubController
  • Method: GET
  • Request: Request
  • Parameters:
    • customerId: Identify the customer for whom the SSO URL is being generated and to retrieve the necessary customer information.
  • Description: Endpoint to generate a rewards platform SSO URL.

The getRewardsPlatformSsoUrl function is used to generate a unique SSO URL for each customer's rewards platform account. This URL allows the customer to log in to the rewards platform directly from the application, without having to enter their credentials again.

public function getRewardsPlatformSsoUrl(Request $request, string $customerId)
{
    // Function implementation goes here
}

Copyright © 2026