To access the Redactor X's API from external scripts, you need to get an instance of the running editor:

var app = RedactorX('#entry');

Or after starting the editor by accessing the element by ID:

var app = RedactorX('#my-element-id');

After that you can call the API commands:

app.editor.insertContent({ html: '<p>Hello world!</p>' });

Multiple editors

If Redactor X is running for multiple elements, it returns instances as an array:

// elements
<textarea class="entry"></textarea>
<textarea class="entry"></textarea>

// call
var app = RedactorX('.entry');

API instances is accessed as below:

app[0].editor.insertContent({ html: '...' });
app[1].editor.insertContent({ html: '...' });

You can also access the API of a specific Redactor X by element ID.

// elements
<textarea id="entry-1" class="entry"></textarea>
<textarea id="entry-2" class="entry"></textarea>

// call

// api
var app1 = RedactorX('#entry-1');
var app2 = RedactorX('#entry-2');

app1.editor.insertContent({ html: '...' });
app2.editor.insertContent({ html: '...' });

API inside plugin

Inside the plugins, you can access to the editor API by using

RedactorX.add('plugin', 'myplugin', {
    start: function() {'mybutton', {
            title: 'My Button',
            icon: '<i class="fa fa-file-alt"></i>',
            command: 'myplugin.insert'
    insert: function() {{
            html: '<p>Hello world!</p>'