text.create
Add a text to a collection. Returns a text object with assigned text id.
Request Parameters
| collection_id | int (required) |
Collection id to store text in. Collection language and text language must be the same.
| body | String (required) |
The body text. Maximum 100 000 chars.
| headline | String |
Text headline. Maximum 250 chars.
| publish_date | String |
Date when the text was published in ISO 8601 format. (YYYY-MM-DDTHH:mm:ssZ)
| url | String |
Publish URL for the text. Maximum 1000 chars.
| authors | String |
Authors who wrote this text. Maximum 100 chars.
| ext_text_id | unique String |
If you want to use your own ids. You can provide both int and strings (e.g. 31241, "AX-321-DD", "My Random String"). The value needs to be unique within a collection or an exception will be raised.
Response Parameters
| text_id | int |
The id for the text.
| collection_id | int |
The collection id for where the text is stored.
| headline | String |
Text headline.
| url | String |
Publish URL for the text.
| ext_text_id | String |
External id for the text
Code Examples
JSON
//Request
{
"method":"text.create",
"params":{
"body":"Hi this is my body text.",
"collection_id":607,
"ext_text_id":"AX-44-D"
},
"id":0
}
//Response
{
"id":0,
"result":{
"headline":"",
"url":"",
"collection_id":607,
"text_id":1,
"ext_text_id":"AX-44-D"
}
}
Java
// You need to have a ready-to-use client to use the other methods
SaploClient client = new SaploClient("YOUR_API_KEY", "YOUR_SECRET_KEY");
// Create a SaploTextManager to work with texts
SaploTextManager textMgr = new SaploTextManager(client);
// Create a text and assign/add it to an existing collection
SaploText text = new SaploText();
text.setCollection(collection);
text.setBody("Contents go here");
// Save/create the text on the Saplo-API
textMgr.create(text);
// Your text gets a generated ID number from the API
System.out.println("This is the ID of the text I added: " + text.getId());
PHP
$client = new SaploAPI("YOUR API KEY", "YOUR SECRET KEY");
$params = array(
"collection_id" => 1,
"headline" => "This is my headline.",
"body" => "This is my awesome body text which I am adding to Saplo API."
);
try {
$result = $client->text->create($params);
} catch(SaploException $e) {
echo '(' . $e->getCode() . ') ' . $e->getMessage();
}
var_dump($result);
Python
client = SaploJSONClient("YOUR API KEY", "YOUR SECRET KEY")
text_id = client.text.create(
collection_id=678,
headline='Example Headline',
body='This is a short example text. Insert a longer one for better results'
)
print "New text created with Id:", text_id
Matlab
params.headline = 'Sweden from Wikipedia';
params.body = 'Sweden shares borders with Norway to the west and Finland to the east, and is connected to Denmark by Ă–resund Bridge.';
params.collection_id = 2131;
response = saploRequest('text.create', params)
sprintf('Text id %s \n', response.text_id);