Tips for working with our API
- Postman and RESTED are good starter tools.
- Make full use of our Testing Console to visualize correct headers.
- RESTED browser extension for Google Chrome gives you access to your rested tabs seamlessly as needed.
- Postman is an API platform that helps beginner and intermediate users build and use APIs in a step by step fashion.
After learning to make successful API calls through the above options, attempt to write your own code. An extension can help you troubleshoot by separating client-code bugs from network issues.
- Always check HTTP and our internal API error codes (described in API docs). No HTTP response signifies something's faulty on the client side.
- Play with our Testing Console (launched from the API docs page). It provides several examples of what works and what doesn't. This console shows how the actual header would look.
- Observe correct formatting for JSON encoding and "urlencoded" encoding of "long_url." Also, don't forget to encode the "user:password" part of the header with base64 encoding. See the description of HTTP Basic authentication.
- "long_url" should be part of the POST payload. And not simply attached to the URL.
Use PHP exception handling to see actual error
messages, like this:
try{
$surl = $client->shorten($url, $data);
}catch(\Exception $e){
print $e->getMessage();
}
Set Content-Type header for HTTP requests.
So headers part would look like this:
headers: {
'Authorization': 'Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'Content-Type': 'application/json',
'Content-Length': message.length
}