We added two new urls. Both urls authenticate the user based on the sessionid cookie.
method: GET
url: /session/json/user/
response:
{
"authenticated": true/false,
"restricted": true/false
}
If 'authenticated' is set to true then the user has an active account at Pdfcrowd and is logged in. The 'restricted' property is send only if the user is authenticated and indicates whether the user has full access to the Pdfcrowd service. This property can be ignored for now.
method: POST
url: /session/json/convert/uri/
content-type: application/x-www-form-urlencoded
post data: src - url to convert to PDF
response:
{
"status" : ok|error|redirect,
"url" : pdf-url|redirect-url,
"message" : error message,
"user" : {
// corresponds to response from /session/json/user
"authenticated": true/false,
"restricted": true/false
}
}
It applies user's default settings and converts 'src' to PDF. On success, 'status' is set to 'ok' and 'url' points to the generated PDF. If an error occurs then 'status' is set to 'error' and 'message' contains the error description. When 'status' is set to 'redirect' then you should open 'url' in the selected or a new tab.
Notes:
- The HTTP status code should be always 200 even if 'status' is set to 'error'.
- It should not happen but please always check that you got a valid JSON response.
- It would be great if you could somehow prevent the user from triggering more than one conversion in parallel - e.g. by graying out the extension button during an ongoing conversion.
- We do not recommend to poll the user status periodically. Instead, you can retrieve the status when the extension starts via /session/json/user/ and then update it after each conversion from the 'response.user' property.
If you are interested, here is a minimalistic
chrome extension example we wrote to test the urls.
That's it. Let us know how it works for you.