Implement a Credit API Workflow
Implement a Credit API Workflow
Your task is to develop a small script or command-line program that interacts with a provided sandbox credit-management API. The API documentation describes operations for account creation, adding credits, checking balances, and spending credits.
Workflow Requirements
The program must perform the following sequence of operations:
- API Discovery: Identify or configure the API's base URL and authentication key. If only runnable examples are provided in the documentation, you are expected to use browser developer tools or a network inspector to extract the actual request URL, headers, and payload format.
- Account Creation: Create a new credit account.
- Credit Top-Up: Add a fixed amount of credits (e.g.,
100credits) to the newly created account. - Balance Check (Initial): Retrieve and print the current balance of the account.
- Credit Spend: Spend a fixed amount of credits (e.g.,
30credits) from the account. - Balance Check (Final): Retrieve and print the final balance of the account.
- Validation: Verify that the final balance is correct based on the initial top-up and subsequent spend amount.
Implementation Constraints
- The implementation should be easy to run.
- It must avoid hardcoding secrets (e.g., API keys).
- It should handle non-successful HTTP responses clearly.
- API calls should be organized into reusable functions.
- AI-assisted coding tools are permitted during this exercise.
AI interview prep
Core dilemma
Balancing the quick delivery of a functional script with the need for robustness, maintainability, and security when interacting with an external API, even for a seemingly simple task.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement a Credit API Workflow
Implement a Credit API Workflow
Your task is to develop a small script or command-line program that interacts with a provided sandbox credit-management API. The API documentation describes operations for account creation, adding credits, checking balances, and spending credits.
Workflow Requirements
The program must perform the following sequence of operations:
- API Discovery: Identify or configure the API's base URL and authentication key. If only runnable examples are provided in the documentation, you are expected to use browser developer tools or a network inspector to extract the actual request URL, headers, and payload format.
- Account Creation: Create a new credit account.
- Credit Top-Up: Add a fixed amount of credits (e.g.,
100credits) to the newly created account. - Balance Check (Initial): Retrieve and print the current balance of the account.
- Credit Spend: Spend a fixed amount of credits (e.g.,
30credits) from the account. - Balance Check (Final): Retrieve and print the final balance of the account.
- Validation: Verify that the final balance is correct based on the initial top-up and subsequent spend amount.
Implementation Constraints
- The implementation should be easy to run.
- It must avoid hardcoding secrets (e.g., API keys).
- It should handle non-successful HTTP responses clearly.
- API calls should be organized into reusable functions.
- AI-assisted coding tools are permitted during this exercise.