Custom integrations with API CALL

API CALL is a special function you can add in the code editor to load custom code from another server in your project.

If you have data or integrations that you want to load on your website (on a back-end level) you can use the API CALL function.

The function can be added in the code editor of page components, layout components, and databases.

Example of API CALL:

[:api_call({
"endpoint_url": "//myserver.domain/myfile.extension",
"api_type": "POST",
"call_type": "live",
"api_headers": {
"header1": "header value 1",
"header2": "header value 2"
},
"api_body": {
"body1": "body value 1",
"body2": "body value 2"
},
"sm_param": true,
"url_param": ["param1", "param2"],
"cms_placeholder": "CMS message"
})/api_call:]

Function

The start and end of an API call looks like this

[:api_call(...)/api_call:]

 

JSON Object

Inside the function, we need a JSON object with the following properties

{
"endpoint_url": "//myserver.domain/myfile.extension",
"api_type": "POST",
"call_type": "live",
"api_headers": {
"header1": "header value 1",
"header2": "header value 2"
},
"api_body": {
"body1": "body value 1",
"body2": "body value 2"
},
"sm_param": "yes",
"cookies": "no",
"url_param": ["param1", "param2"],
"cms_placeholder": "CMS message"
}

 

JSON Properties

The following properties need to be present for the call to work properly.

endpoint_url

This is the link to the file on your custom server

api_type

You can choose between "POST" and "GET".

call_type

You can choose between "live" and "publish". A "live" API call will be executed when the page is loaded. A "publish" API call will be executed when the website is published. When the call data doesn't change much the "publish" option will make fewer calls then a "live" call_type.

api_headers

You can send additional headers to your endpoint_url.

"api_headers": {
"header1": "header value 1",
"header2": "header value 2"
}

Add one or multiple properties to api_headers

You can integrate API Keys & Tokens or CMS variables inside these properties

https://support.sitemanager.io/code#token-management

Example of api_header with a token value

"api_headers": {
"AuthToken": "[::TKN::APITOKEN::]",
}

Example of api_header with CMS variable

"api_headers": {
"ButtonLabel": "[:swvar:text:138:]",
}

api_body

You can send additional body parameters to your endpoint_url.

"api_body": {
"body1": "body value 1",
"body2": "body value 2"
}

These parameters can be send similar to header parameters but they will be send as POST or GET variables, depending on the API type you have set.

sm_param

Send the SiteManager parameters to the endpoint_url. Set to "yes" or "no".

The SiteManager parameters are:

sm_lang_id: the language id of the project

sm_lang_code: the language country code of the project

sm_lang_folder: the language folder of the project (mutlilingual languages)

sm_page_id: the current page id of the project

sm_project_name: the unique project name

These parameters will be sent as GET or POST depending on api_type

cookies

Save the cookies set in the API call to cookies on the main website. Set to "yes" or "no".

url_param

URL parameters will be sent if set from the page URL where the API is called to your endpoint_url.
These parameters will only work when the call_type is set to "live".

"url_param": ["company_id", "fbid"],

You can sent multiple URL parameters to the endpoint_url.

cms_placeholder

This is the piece of code that will be shown inside the SiteManager CMS.

Make sure the placeholder code is using single quotes and does not use enters. This will break the JSON object.