WHMCS API may use different authentication methods for different areas of the API.
For store and cart operations, use an X-Api-State header if the cart belongs to a logged-in user. The X-Api-State header represents a state of the cart. Each response returns a new value, and each request must include the latest value.
For example, the following request includes the X-Api-State header:
curl -X GET --location "https://example.com/api/v2/cart/TLlowSWlQjGkGrC1"
-H "X-Api-State: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd2htY3MtZGV2LnRlc3RcLyIsImF1ZCI6Imh0dHBzOlwvXC93aG1jcy1kZXYudGVzdFwvIiwiZXhwIjoxNjQ3NTYzMzI3LCJzdWIiOltdLCJ3aG1jc191c2VyIjoiMzlhNDA0NTFlOGE4NjhhZWI4NjExYzEwNGE5OTYwMzk2NmM2MmIyMzg0YWYyYjc4OWJhOGU2YmYxYWVhYjMzYSJ9.B4-Ug6AcVCI52woiW9dF_ylYZXf57e32RSk_7S78Z9M"The following example request adds a payload:
curl -X POST --location "https://example.com/api/v2/cart/6isLR0SAB0TbCiws/promotions"
-H "Content-Type: application/json"
-H "X-Api-State: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd2htY3MtZGV2LnRlc3RcLyIsImF1ZCI6Imh0dHBzOlwvXC93aG1jcy1kZXYudGVzdFwvIiwiZXhwIjoxNjQ3MzkyODM1LCJzdWIiOltdLCJ3aG1jc191c2VyIjoiMzlhNDA0NTFlOGE4NjhhZWI4NjExYzEwNGE5OTYwMzk2NmM2MmIyMzg0YWYyYjc4OWJhOGU2YmYxYWVhYjMzYSJ9.LfYOrxW5OOtdcfyDOuIa6B0dTytYROMrccqpywxvAB8"
-d "{\"code\":\"CARTAPI\"}"To log in, you must include the user's email address and password.
For example:
curl -X POST --location "https://example.com/whmcs/api/v2/user/session"
-H "Content-Type: application/json"
-d "{\"email\":\"[email protected]\",\"password\":\"pwd123456\"}"If the user has enabled Two-Factor Authentication (2FA), send an additional request to verify the 2FA token before authenticating the user.
For example:
curl -X POST --location "https://example.com/whmcs/api/v2/user/session/verify"
-H "Content-Type: application/json"
-H "X-Api-State: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd2htY3MtZGV2LnRlc3RcLyIsImF1ZCI6Imh0dHBzOlwvXC93aG1jcy1kZXYudGVzdFwvIiwiZXhwIjoxNjQ3NDQwMzc5LCJzdWIiOiI1MzJlZmM4ZmI5NzA2NDQ4ZDZkMDMwMTc1ZmFlY2U3N2QxN2E5OGRjN2FkNTZlZWZhZmZjYTRmNzY2ZDJiZjE4In0.Igj9Kby5FR5m4w03x92NwuKviCLRQBQUaLbaXTqQ9kc"
-d "{\"fields\":{\"key\":\"417339\"}}"