\u003Cfigcaption>Reproduce the issue in a developer tool, like Postman, for deeper inspection\u003C/figcaption>\u003C/figure>\n\u003C!-- /wp:image -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>If you want to import an API call into Postman, you can \u003Ca href=\"https://learning.postman.com/docs/getting-started/importing-and-exporting-data/#importing-postman-data\">paste a cURL command\u003C/a> as raw text. You can also \u003Ca href=\"https://learning.postman.com/docs/sending-requests/capturing-request-data/interceptor/\">capture a sequence of calls with a proxy\u003C/a> for replay or recording. \u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:heading {\"level\":3} -->\n\u003Ch3 id=\"h-check-the-status-messages\">Check the status messages\u003C/h3>\n\u003C!-- /wp:heading -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>When you’re talking to an API, the server returns an \u003Ca href=\"https://datatracker.ietf.org/doc/html/rfc7231#section-6\">HTTP status code\u003C/a> that signals the status of your API request. Status codes and error messages are determined by the API provider, so they vary in meaningfulness and accuracy. But most API providers follow the established convention of defining the class of response using the first digit of their status code. For example, status codes in the 400s indicate an issue with the client. This means that you can update the request to potentially solve the issue. Status codes in the 500s indicate an issue with the server. Besides verifying that you are accessing the proper resource and checking back later, there’s not much you can do unless you are also the API provider.\u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>Assuming the server returns reliable status messages, this is our first clue to tracking down the source of the bug. Here are some common client error codes in the 400s and what you can do when you encounter one of these errors: \u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:list -->\n\u003Cul>\u003Cli>\u003Ca href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400\">400 Bad Request\u003C/a>: Look for syntax errors like typos or a malformed JSON body.\u003C/li>\u003Cli>\u003Ca href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401\">401 Unauthorized\u003C/a>: Verify that you have valid authentication credentials for the target resource and check your syntax for header values.\u003C/li>\u003Cli>\u003Ca href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403\">403 Forbidden\u003C/a>: Check your permissions and scope to ensure you are authorized to access the resource.\u003C/li>\u003Cli>\u003Ca href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418\">418 I’m a Teapot\u003C/a>: May indicate the request is one the provider does not want to handle, such as automated queries.\u003C/li>\u003Cli>\u003Ca href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429\">429 Too Many Requests\u003C/a>: Check the documentation to understand the rate limits or try again later.\u003C/li>\u003C/ul>\n\u003C!-- /wp:list -->\n\n\u003C!-- wp:image -->\n\u003Cfigure class=\"wp-block-image\">\u003Cimg src=\"https://lh6.googleusercontent.com/ZtNSbhohrBwfyf5lC8t4nv8mPg-1cvA7razZBKUglCfAn5vvgfnGzRYSDSObNQLGy_fA7xWM8zA8YJc9QeV9BNqInLOQz9pKfPoptvhDPgu7AsNat7V7xZSHvnrsicrEVpcHC-y-\" alt=\"The Postman interface showing a 401 Unauthorized error response from an API call. \"/>\u003Cfigcaption>HTTP status codes in the 400s indicate a client error\u003C/figcaption>\u003C/figure>\n\u003C!-- /wp:image -->\n\n\u003C!-- wp:heading {\"level\":3} -->\n\u003Ch3 id=\"h-inspect-the-data-more-deeply\">Inspect the data more deeply\u003C/h3>\n\u003C!-- /wp:heading -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>The next step is to dig deeper and validate your assumptions. You can validate that you have formatted each request properly and parsed each response correctly. You can also validate that variables are defined and referenced properly as you pass data along a sequence of API calls.\u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>Here are common issues when dealing with HTTP APIs:\u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:list -->\n\u003Cul>\u003Cli>\u003Cstrong>Malformed JSON:\u003C/strong> Newcomers make some common mistakes when sending JSON bodies. Single quotes are invalid within the JSON string, so make sure you surround strings and property names with double quotes. Additionally, comments are not supported by JSON, so either minify them or don’t add them at all. \u003C/li>\u003Cli>\u003Cstrong>Serializing data:\u003C/strong> REST APIs frequently store and send data as JSON objects. For the data to transmit properly, make sure to encode the data with \u003Ccode>JSON.stringify()\u003C/code> and decode it with \u003Ccode>JSON.parse()\u003C/code>. Additionally, servers may require that you set a \u003Ccode>Content-Type\u003C/code> header with the value of \u003Ccode>application/json\u003C/code>. Upon further inspection, if you see values like \u003Ccode>[object Object]\u003C/code> or \u003Ccode>Unexpected token\u003C/code>, this indicates improper serialization and deserialization.\u003C/li>\u003Cli>\u003Cstrong>Type casting:\u003C/strong> Values can be cast from one type to another as you prepare to send a request or parse a response. Depending on the programming language, performing a math calculation on a \u003Ccode>string\u003C/code> may fail, but casting the value to a \u003Ccode>number\u003C/code> allows you to work with the data.\u003C/li>\u003Cli>\u003Cstrong>Extracting information:\u003C/strong> Once you deserialize a JSON response using \u003Ccode>JSON.parse()\u003C/code>, you can \u003Ca href=\"https://stackoverflow.com/a/11922384\">access properties\u003C/a> with dot or bracket notation and loop through arrays. If you are trying to access deeply nested information within a complex structure, you may need to break it down step-by-step to precisely reference that information and guarantee that you are not trying to drill deeper into something that is \u003Ccode>undefined\u003C/code>.\u003C/li>\u003Cli>\u003Cstrong>Authentication vs. authorization:\u003C/strong> Authentication verifies users are who they say they are, while authorization confirms that users have permission to access a resource. If you have the proper authorization header(s) included with a request but still cannot access a resource, doublecheck the permissions and scopes associated with your credentials.\u003C/li>\u003Cli>\u003Cstrong>Content type headers:\u003C/strong> The \u003Ccode>Content-Type\u003C/code> and \u003Ccode>Accept\u003C/code> headers facilitate the content negotiation between client and server. A \u003Ccode>Content-type\u003C/code> request header tells the server what type of information is being sent from the client. On the other hand, an \u003Ccode>Accept\u003C/code> request header tells the server what type of content the client can understand. Some APIs require specific request headers and only work with certain content types. \u003C/li>\u003C/ul>\n\u003C!-- /wp:list -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>With these common errors, you can rely on syntax highlighting, linters, and other inspection features to provide more visibility into issues. Developer consoles can also provide more visibility into your application’s network calls and log statements to further help you isolate issues with inputs, outputs, and passing data from one call to another. For example, if you have a sequence of synchronous or asynchronous calls, logging values at critical junctions or setting up conditional breakpoints can help you quickly pinpoint the issue. Using console statements like \u003Ccode>console.log()\u003C/code> throughout the call execution can further validate your assumptions parsing outputs.\u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:image -->\n\u003Cfigure class=\"wp-block-image\">\u003Cimg src=\"https://lh3.googleusercontent.com/15fjGE5YzOJpM9idn_sedHCX_Pl2uTDZGJfg12gQVFW5ygQ12T1zZfAS-n8H5vejqM33gufjjIaNjkzPdp4OnXISCAUrWBRJ-FX54GtTLdzq_Sh40sHgNunKdIc2ozyPMzumk8kv\" alt=\"The Postman interface showing the console log results from a test. \"/>\u003Cfigcaption>Use consoles for visibility into network calls, call execution order, and variable values\u003C/figcaption>\u003C/figure>\n\u003C!-- /wp:image -->\n\n\u003C!-- wp:heading -->\n\u003Ch2 id=\"h-types-of-debugging-strategies\">\u003Cstrong>Types of debugging strategies\u003C/strong>\u003C/h2>\n\u003C!-- /wp:heading -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>A number of debugging strategies can narrow down the cause of the issue. These strategies fall into three general categories. \u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:heading {\"level\":3} -->\n\u003Ch3 id=\"h-brute-force-strategy\">Brute force strategy\u003C/h3>\n\u003C!-- /wp:heading -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>If you have limited observability into a system, this means that you are tweaking and logging everything. Adding strategic log statements at certain points throughout a sequence of API calls can be helpful. However, the volume of logs has diminishing returns as it takes more time to interpret the logged data.\u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:heading {\"level\":3} -->\n\u003Ch3 id=\"h-backtracking-strategy\">Backtracking strategy\u003C/h3>\n\u003C!-- /wp:heading -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>This strategy refers to moving backwards from the point where an error is first observed to find the root cause. Similarly, you can start from an API call that is displaying behavior you expect, and then step through subsequent calls until you find the bug. This strategy works well when you have reasonable hypotheses of what might be causing the problem, but is less effective when the error is far from the root cause.\u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:heading {\"level\":3} -->\n\u003Ch3 id=\"h-divide-and-conquer-strategy\">Divide-and-conquer strategy\u003C/h3>\n\u003C!-- /wp:heading -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>In complex systems, breaking the system into smaller sections may allow you to spot problems more easily.\u003Cstrong> \u003C/strong>Binary search is one example of this strategy, where you input a log statement or breakpoint in the middle of a longer sequence of calls. If the defect does not occur by that breakpoint, repeat the process with the second half of the calls, and so on. Another strategy is to use mock servers to isolate the system under test. You can rely on mock responses to stub external dependencies or provide a starting point for your scenarios. \u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:heading -->\n\u003Ch2 id=\"h-get-in-the-debugging-mindset\">\u003Cstrong>Get in the debugging mindset\u003C/strong>\u003C/h2>\n\u003C!-- /wp:heading -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>After a while, focusing on a problem without making progress can become counterproductive as you lose sight of the forest for the trees. The following tactics can help you get in a more effective debugging mindset. \u003C/p>\n\u003C!-- /wp:paragraph -->\n\n\u003C!-- wp:list -->\n\u003Cul>\u003Cli>\u003Cstrong>Rubber duck debugging:\u003C/strong> Articulating the problem and hypothesis to someone else may shift your own perspective by forcing you to slow down and explicitly state your assumptions. \u003C/li>\u003Cli>\u003Cstrong>Switch from a focused to diffused mode\u003C/strong>: Switching to a different activity altogether, like taking a hike, moves your brain into a different gear. The diffused mode of learning is when your brain passively establishes new connections and may result in creative insights. This is one reason why you get the best ideas in the shower or when you first wake up.\u003C/li>\u003C/ul>\n\u003C!-- /wp:list -->\n\n\u003C!-- wp:heading -->\n\u003Ch2 id=\"h-save-time-and-heartache-while-debugging\">\u003Cstrong>Save time and heartache while debugging\u003C/strong>\u003C/h2>\n\u003C!-- /wp:heading -->\n\n\u003C!-- wp:paragraph -->\n\u003Cp>Whether you are new to consuming REST APIs or a seasoned veteran, a consistent and methodical approach to debugging saves time and heartache. The debugging strategy you choose depends on the observability of the system. If your system has extensive monitoring in place with predefined logs and stack traces, you can uncover issues quickly and may be able to spot the bug right away. If these measures aren’t in place, you can simplify the problem to reduce the search area and utilize some of these debugging tactics for more visibility. \u003C/p>\n\u003C!-- /wp:paragraph -->","html","2022-02-28T15:01:18.000Z",{"current":687},"debugging-best-practices-for-rest-api-consumers",[689,697,702,706,711,715],{"_createdAt":690,"_id":691,"_rev":692,"_type":693,"_updatedAt":690,"slug":694,"title":696},"2023-05-23T16:43:21Z","wp-tagcat-api","9HpbCsT2tq0xwozQfkc4ih","blogTag",{"current":695},"api","API",{"_createdAt":690,"_id":698,"_rev":692,"_type":693,"_updatedAt":690,"slug":699,"title":701},"wp-tagcat-code-for-a-living",{"current":700},"code-for-a-living","Code for a Living",{"_createdAt":690,"_id":703,"_rev":692,"_type":693,"_updatedAt":690,"slug":704,"title":705},"wp-tagcat-debugging",{"current":705},"debugging",{"_createdAt":690,"_id":707,"_rev":692,"_type":693,"_updatedAt":690,"slug":708,"title":710},"wp-tagcat-rest-api",{"current":709},"rest-api","rest api",{"_createdAt":690,"_id":712,"_rev":692,"_type":693,"_updatedAt":690,"slug":713,"title":714},"wp-tagcat-testing",{"current":714},"testing",{"_createdAt":716,"_id":717,"_rev":718,"_type":693,"_updatedAt":719,"description":720,"slug":729,"title":730},"2025-04-24T16:28:57Z","797b8797-6e65-4723-b53f-8bc005305384","vn3UzGZJyacwgllS8WZNgc","2025-04-24T16:29:32Z",[721],{"_key":722,"_type":65,"children":723,"markDefs":728,"style":73},"bb32f75814b4",[724],{"_key":725,"_type":69,"marks":726,"text":727},"dbcf27ef29b3",[],"Community-generated articles submitted for your reading pleasure. ",[],{"_type":10,"current":730},"contributed","Debugging best practices for REST API consumers",[733,739,745,751],{"_id":734,"publishedAt":735,"slug":736,"sponsored":12,"title":738},"370eca08-3da8-4a13-b71e-5ab04e7d1f8b","2025-08-28T16:00:00.000Z",{"_type":10,"current":737},"moving-the-public-stack-overflow-sites-to-the-cloud-part-1","Moving the public Stack Overflow sites to the cloud: Part 1",{"_id":740,"publishedAt":741,"slug":742,"sponsored":676,"title":744},"e10457b6-a9f6-4aa9-90f2-d9e04eb77b7c","2025-08-27T04:40:00.000Z",{"_type":10,"current":743},"from-punch-cards-to-prompts-a-history-of-how-software-got-better","From punch cards to prompts: a history of how software got better",{"_id":746,"publishedAt":747,"slug":748,"sponsored":12,"title":750},"65472515-0b62-40d1-8b79-a62bdd2f508a","2025-08-25T16:00:00.000Z",{"_type":10,"current":749},"making-continuous-learning-work-at-work","Making continuous learning work at work",{"_id":752,"publishedAt":753,"slug":754,"sponsored":12,"title":756},"1b0bdf8c-5558-4631-80ca-40cb8e54b571","2025-08-21T14:00:25.054Z",{"_type":10,"current":755},"research-roadmap-update-august-2025","Research roadmap update, August 2025",{"count":758,"lastTimestamp":759},2,"2023-05-25T09:47:44Z",["Reactive",761],{"$sarticleModal":762},false,["Set"],["ShallowReactive",765],{"sanity-xHJT3yVcbAYZnL5je4wA981TuwJlT32_LqwBqRp-nSc":-1,"sanity-comment-wp-post-19686-1756473980602":-1},"/2022/02/28/debugging-best-practices-for-rest-api-consumers/?cb=1"]