SMMRY API
Developers are able to implement SMMRY into applications that may require a summarization of a webpage or block of text. Developers will need a SMMRY API key in order to access the API.
API Key
To receive an API key, you'll need a
Partner account.
Firstly get a free account
here. Once registered head to the
partner page and click upgrade. An API key will be generated automatically.
Modes
There are two active modes of the SMMRY API, Free and Full:
Free: A limit of 100 free API requests can be made daily, and each request must be at least 10 seconds apart. If a request was made too soon, the API will wait the required time before fulfilling the request.
Full: An unlimited amount of requests can be made with no artificial time limit in between. 1 credit costs $0.001, or a tenth of a cent. It costs approximately 1 credit per 500 characters returned by the API (only summarized content is counted). It costs an additional 8 credits if the article has not been previously submitted and cached by the algorithm, that way re-summarizing the same article is cheaper. When credit costs are being calculated, decimals are rounded upwards.
You can switch between modes via your
Partner account page. (you can also find your API key listed there!)
Requests
The API request must be made to
https://api.smmry.com. The returned response will be encoded in
JSON.
Here are the possible parameters placed in the request URL.
• SM_API_KEY=N |
Required, your API key. |
• SM_URL=X |
Optional, the webpage to summarize. |
• SM_LENGTH=N |
Optional, the number of sentences returned, default 7. |
• SM_KEYWORD_COUNT=N |
Optional, N the number of keywords to return. |
• SM_WITH_BREAK |
Optional, inserts the string [BREAK] between sentences. |
• SM_WITH_ENCODE |
Optional, converts HTML entities to their applicable chars. |
• SM_IGNORE_LENGTH |
Optional, returns summary regardless of quality or length. |
• SM_QUOTE_AVOID |
Optional, sentences with quotations will be excluded. |
• SM_QUESTION_AVOID |
Optional, sentences with question will be excluded. |
• SM_EXCLAMATION_AVOID |
Optional, sentences with exclamation marks will be excluded. |
Here are the possible indexes of the array returned in a JSON array.
• sm_api_message |
Contains notices, warnings, and error messages. |
• sm_api_character_count |
Contains the amount of characters returned. |
• sm_api_title |
Contains the title when available. |
• sm_api_content |
Contains the summary. |
• sm_api_keyword_array |
Contains top ranked keywords in descending order. |
• sm_api_error |
Contains error code. |
The maximum number of sentences returned is 40. When using SM_WITH_BREAK, make sure to replace the [BREAK] strings with whatever you want to seperate each sentence ('/n', '<br>' etc). Also, make sure any webpage URL sent to summarize is accessible to SMMRY, pages requiring authentication won't do.
PHP Example - Summarize TextHere is an example of PHP using cURL to summarize a block of text:
$text = "Your long text goes here...";
$ch = curl_init("http://api.smmry.com/&SM_API_KEY=X");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:")); // See Note
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "sm_api_input=".$text);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$return = json_decode(curl_exec($ch), true);
curl_close($ch);
Note: The option CURLOPT_HTTPHEADER is required and should not be removed.
You're summary will be stored in $return['sm_api_content'].
PHP Example - Summarize External WebpageHere is an example of PHP using cURL to summarize an external webpage:
$ch = curl_init("http://api.smmry.com/&SM_API_KEY=X&SM_URL=http://abc.com");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,20);
curl_setopt($ch, CURLOPT_TIMEOUT,20);
$return = json_decode(curl_exec($ch), true);
curl_close($ch);
Note: The parameter &SM_URL= should always be at the end of the request url to avoid complications.
You're summary will be stored in $return['sm_api_content'].
Error Codes
0 - Internal server problem which isn't your fault
1 = Incorrect submission variables
2 - Intentional restriction (low credits/disabled API key/banned API key)
3 - Summarization error