text.create

Add a text to a collection. Returns a text object with assigned text id.

Request Parameters

collection_idint (required)
Collection id to store text in. Collection language and text language must be the same.
bodyString (required)

The body text. Maximum 100 000 chars.

headlineString
Text headline. Maximum 250 chars.
publish_dateString

Date when the text was published in ISO 8601 format. (YYYY-MM-DDTHH:mm:ssZ)

urlString

Publish URL for the text. Maximum 1000 chars.

authorsString

Authors who wrote this text. Maximum 100 chars.

ext_text_idunique 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.

forceboolean (default: false)

Set to true to force a text into provided collection. Used in cases when your text is rejected but you know the text language matches the collection language.

Warning! If your text doesn't match your collection language it strongly effects the result.

Response Parameters

text_idint
The id for the text.
collection_idint
The collection id for where the text is stored.
headlineString
Text headline.
urlString
Publish URL for the text.
ext_text_idString

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);