Skip to content

Generating Content

Once you have a template written and ready to go, you can publish the article using the editor. Once published, you can use the id of the published template to generate your content using one of the following endpoints.

Endpoints

Depending on how you have set up your data source, you can either make a GET or a POST request to these endpoints. See the Custom Data Source overview for an explanation of the differences.

GET https://api.icrobotic.com/templates/{id}/generate?contentId={contentId}

or

GET https://api.icrobotic.com/templates/{id}/{contentId}/generate

where id is the id of your published template, and contentId is the id of some content in your data source.

Note

When using the GET endpoints, it is necessary to set up the search and data endpoints, as described in the Data Endpoints page.

POST https://api.icrobotic.com/templates/{id}/generate?contentId={contentId}

or

POST https://api.icrobotic.com/templates/{id}/{contentId}/generate

where id is the id of your published template, and contentId is the id of some content in your data source.

Note

It is important the the variables (names and types) from the test data, which is used to build the template, matches the variables provided in the body, when generating the content.

When using the POST version of the endpoint, the body must contain the data, as described in the Data Format page.

Request body example
{
    "Variables": [
        {
            "Type": "Text",
            "Name": "Variable1",
            "Value": "Value1"
        },
        {
            "Type": "Number",
            "Name": "Variable2",
            "Value": 2
        },
        { 
            "Type": "Date",
            "Name": "Variable3",
            "Value": "2020-01-01T18:00:00"
        },
        {
            "Type": "List",
            "Name": "Variable4",
            "Value": ["ListValue1", "ListValue2", "ListValue3"]
        },
        {
            "Type": "Bool",
            "Name": "Variable5",
            "Value": true
        }
    ]
}

For more details, see the Data Format page.

Response

All of these endpoints will combine your data and the template to produce a response of the following form:

{
    "metadata": .. metadata given in the data endpoint ..,
    "mysection": "This is dummy text!",
    "myothersection": "This is also dummy text!",
}

Where metadata is only there if it is provided in your data. Each section in your template will generate a property, the name of which will be a json-friendly version of your section name (mysection and myothersection in this example). The value of each section-property will be a string containing the result of the generation for that section.

Errors

In case something goes wrong, the endpoints will return an error code. Some common errors are listed below.

This error is returned when there is a problem authenticating, such as a missing or wrong API key:

{
    "Message": "Unauthorized",
    "Time": "2020-01-01T00:00:00.000Z"
}

or if the API key does not have the right scopes:

{
    "Message": "Missing scope(s): template_generate",
    "Time": "2020-01-01T00:00:00.000Z"
}

This error occurs when a wrong id for the publication is used in the endpoint, with the following message:

{
    "Message": "Template with id '123' not found.",
    "Time": "2020-01-01T00:00:00.000Z"
}

Hint

Make sure the id parameter matches the id of the publication in the IC Robotics platform.

If any other error occurs, this status code is return, with the following message:

{
    "Message": "An error occured. Please try again, if the problem persists, please contact us at contact@icrobotic.com",
    "Time": "2020-01-01T00:00:00.000Z"
}

When using the POST endpoint, this status code can also be returned if there is a problem parsing the variables in the body of the request. If this occurs, please verify that the format matches the format specified in the Data Format page.

{
    "Message": "Failed to parse response from source as a list of variables. Please see documentation for assistance.",
    "Time": "2020-01-01T00:00:00.000Z"
}