REST API v4: PUT hyperlink extensions (drag and drop template)

This method can be used to configure the hyperlink extensions of a Marketing Suite (drag and drop) template. By sending a PUT request to the following URL, you can create, update or remove hyperlink extension rules:

https://api.copernica.com/v4/draganddrop/template/$id/hyperlinkextensions

The $id should be replaced with the numeric identifier of the template.

The complete hyperlink extension configuration should be sent in the request body.

Sending an empty array removes all hyperlink extensions from the template.

Body data

The request body should contain an array of hyperlink extension rules.

Each rule can contain the following fields:

  • parameter: the URL parameter to add or update
  • value: the value of the URL parameter
  • type: determines which action is performed on the hyperlink. Currently only setparameter is supported; this adds or updates a URL parameter
  • last: whether processing should stop after this rule
  • unique: whether the rule should be skipped if a previous rule has already modified the same URL
  • checks: conditions that determine when the rule should be applied

The following check types are supported:

  • domain: checks the domain of the URL;
  • path: checks the path of the URL;
  • parameter: checks an existing URL parameter;
  • protocol: checks the protocol of the URL, for example http or https.

Domain, path and parameter checks support the following comparison types:

  • equals: the value must match exactly
  • notequals: the value must not match
  • contains: the value must contain the specified text
  • notcontains: the value must not contain the specified text
  • match: compares the value using a glob pattern. Wildcards such as * and ? can be used and the comparison is case-insensitive
  • regex: compares the value using a regular expression via PHP preg_match()

JSON example

The following JSON demonstrates how to configure hyperlink extensions:

[
    {
        "parameter": "utm_source",
        "value": "copernica",
        "type": "setparameter",
        "last": false,
        "unique": false,
        "checks": []
    },
    {
        "parameter": "utm_content",
        "value": "link",
        "type": "setparameter",
        "last": false,
        "unique": false,
        "checks": [
            {
                "type": "domain",
                "value": "copernica.com",
                "comparison": "contains"
            }
        ]
    }
]

PHP example

The following PHP script calls this API method:

// dependencies
require_once('CopernicaRestAPI.php');

// change this into your access token
$api = new CopernicaRestAPI("your-access-token", 4);

// hyperlink extension configuration
$data = array(
    array(
        'parameter' => 'utm_source',
        'value'     => 'copernica',
        'type'      => 'setparameter',
        'last'      => false,
        'unique'    => false,
        'checks'    => array()
    )
);

// do the call
print_r($api->put("draganddrop/template/{$templateID}/hyperlinkextensions", $data));

The example above requires the CopernicaRestApi class.

More information