|
| 1 | +--- |
| 2 | +keywords: ['api', 'error', 'client'] |
| 3 | +slug: /api-troubleshooting-client-server-errors-during-the-api-call |
| 4 | +title: Client-Server Errors during the API call |
| 5 | +--- |
| 6 | +# Client-Server Errors During the API Call |
| 7 | + |
| 8 | + |
| 9 | +When working with APIs, one of the most common hurdles developers face is understanding and resolving errors that occur during the interaction between a client and a server. Whether you're building, integrating, or consuming APIs, it's important to recognize what different error codes mean and how to fix them. These errors are typically categorized as client-side or server-side, each with its own set of HTTP status codes. |
| 10 | + |
| 11 | +This guide will walk you through the most common client-server error codes encountered during API calls, explain what they mean, and offer practical tips for diagnosing and resolving them effectively. Whether you're a beginner trying to understand what a 404 error really means or an experienced developer dealing with elusive 5XX responses, this article will help you decode the problem and get your API calls back on track. |
| 12 | + |
| 13 | +## Application Programming Interfaces (APIs) |
| 14 | + |
| 15 | +APIs allow two programs to communicate and transfer data. An API call is when a client application submits a request to an API, which retrieves the requested data from an external server or program and delivers it back to the client. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Error Status Codes When Building APIs |
| 20 | + |
| 21 | +### 1. Client-Side Status Codes |
| 22 | + |
| 23 | +- #### 404 Not Found |
| 24 | + This is the most common HTTP status code. It indicates that the URL used in your request doesn’t exist on the API server or origin server. While this is a 4XX error (usually meaning something on the client-side is wrong), it can also indicate a server problem. Sometimes API URL paths change after a version update, or due to server issues. |
| 25 | + |
| 26 | + :::tip |
| 27 | + Check for typos in your client code before investigating API issues. |
| 28 | + ::: |
| 29 | + |
| 30 | +  |
| 31 | + |
| 32 | +- #### 401 Unauthorized |
| 33 | + This status code means you haven’t authenticated against the API. The API doesn’t know who you are and won’t serve you. For most APIs, you need to sign up and get an API key, which is used in an HTTP header field when sending a request. |
| 34 | + |
| 35 | + This is similar to the less common **407 Proxy Authentication Required**, which means you haven’t authenticated with the proxy. |
| 36 | + |
| 37 | +  |
| 38 | + |
| 39 | +- #### 403 Forbidden |
| 40 | + This status indicates you don’t have permission to request that URL. You’re authenticated, but your user or role isn’t permitted to make the API request. This can also occur if you use the wrong API key or try to access features not allowed by your subscription plan. |
| 41 | + |
| 42 | +  |
| 43 | + |
| 44 | +- #### 400 Bad Request |
| 45 | + The *400 Bad Request* error is generic. It means your API request was not correctly formatted. If no additional error information is given in the response body, check the docs. You could be missing a query, a field in the request body, or a header field could be wrong. Incorrect syntax in your request data can also cause this. |
| 46 | + |
| 47 | + This differs from the *422 Unprocessable Entity* error, which appears when your request is correctly formatted but cannot be processed. For example, passing a badly formatted `latlang` value to the API (e.g., missing a comma). |
| 48 | + |
| 49 | +  |
| 50 | + |
| 51 | +- #### 429 Too Many Requests |
| 52 | + Most API subscription plans have limits—the cheaper the plan, the fewer requests per second are allowed for your API key. If you send too many requests in a short time, consider throttling them in your client. This response can also indicate you hit a daily, weekly, or monthly limit on your account. |
| 53 | + |
| 54 | + :::tip |
| 55 | + Check your API subscription limits before integrating, or you may run into problems later. |
| 56 | + ::: |
| 57 | +--- |
| 58 | + |
| 59 | +### 2. Server-Side Status Codes |
| 60 | + |
| 61 | +Sometimes, server-side API errors occur. Here are common ones: |
| 62 | + |
| 63 | +- #### 500 Internal Server Error |
| 64 | + This code can mean anything, but usually indicates the API server crashed. It could be caused by your API call or by buggy code/data from an upstream service. Double-check the docs for correct query fields, body fields, headers, and format. If the problem persists, contact the API’s support. |
| 65 | + |
| 66 | +- #### 502 Bad Gateway |
| 67 | + This response means the server you called was a gateway or proxy, not the actual API server. The proxy tried to call the API server but didn’t get a response. This could be a network problem, server crash, or maintenance. Usually, this is temporary and should be solved by the API provider. |
| 68 | + |
| 69 | +- #### 503 Service Unavailable |
| 70 | + This status indicates a server error—too many API requests were sent and the API can’t handle more. The problem usually resolves itself when clients send fewer requests, but it could also mean the API provider didn’t plan enough resources. If the error persists, contact the API provider. |
| 71 | + |
| 72 | +- #### 504 Gateway Timeout |
| 73 | + Like 502, this means the server you called is a proxy for the real API server, but the API server took too long to respond. This could be due to high network latency or a slow API server. Try reducing the amount of data or complexity of your request. If the error persists, contact support. |
| 74 | + |
| 75 | +- #### 501 Not Implemented |
| 76 | + This status code is related to the HTTP method you used. Try a different HTTP method. Usually, an inappropriate method results in a 404, but 501 means the method isn’t implemented yet and may be available in the future. |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +You’ll encounter many error codes when using APIs, but most have reasonable fixes. Some are server errors, some are client-side errors, and often one can cause the other. |
| 81 | + |
| 82 | + |
| 83 | +:::tip |
| 84 | +Always read the docs and API notes thoroughly. If things are broken, contact the API provider or search for answers on the web (e.g., StackOverflow). Stay determined, and you’ll see your 200 OK status codes in no time! |
| 85 | +::: |
| 86 | + |
| 87 | + |
0 commit comments