Widget create
Endpoint POST /widgets
Create a new widget.
Body Parameters
Required
type
- The type of the widget (bracket
,comparison_table
,chart
, etc.)name
- The name of the widgetstatus
- The status of the widget (draft
orpublished
)
Optional
data
- The widget's data. The structure of this data will depend on the widget type. You can explore the different schemas with the Widget Data Explorer Tool tool. If not provided, a default data will be used.description
- The description of the widgetprojectId
- The related project ID of the widgetmodelVersion
- The version of the widget's data model. This is used to determine the schema of thedata
field. If not provided, the latest version will be used.
Example Request:
- curl
- Node.js
curl -X POST -H "Authorization: Bearer ACCESS_TOKEN" -H "Content-Type: application/json" -d '{ "name": "New Widget", "type": "bracket", "data": {} }' "https://api.commoninja.com/platform/api/v1/widgets"
const axios = require('axios');
async function getData() {
const data = {
name: 'New Widget',
type: 'bracket',
data: {}
};
const response = await axios.post('https://api.commoninja.com/platform/api/v1/widgets', data, {
headers: {
'Authorization': 'Bearer ACCESS_TOKEN',
'Content-Type': 'application/json'
}
});
return response.data;
}
getData();
Example Response:
{
"id": "894f5aed-29f5-46c5-9f26-022bfccc5292",
"name": "New Widget",
"description": "",
"type": "comparison_table",
"previewImage": "",
"projectId": "",
"status": "draft",
"modelVersion": 1,
"created": "2023-04-25T09:44:42.842Z",
"updated": "2023-04-25T09:44:42.842Z",
"data": {},
"embedCode": {
"html": "<div class=\"commonninja_component pid-894f5aed-29f5-46c5-9f26-022bfccc5292\"></div>",
"script": "<script src=\"https://cdn.commoninja.com/sdk/latest/commonninja.js\" defer></script>"
},
"editorUrl": "https://www.commoninja.com/comparison-tables/editor/view/894f5aed-29f5-46c5-9f26-022bfccc5292"
}