REST API v4: PUT collection subprofiles

If you want to modify multiple subprofiles with a single call to the API, you can send a HTTP PUT request to the following URL:

https://api.copernica.com/v4/collection/$id/subprofiles

The $id code should be replaced with the numeric identifier or the name of the collection in which you want to modify subprofiles. The new field values should be sent in the request body.

Please keep in mind that this is a HTTP PUT request. This method is an exception to the rule that the Copernica REST API makes no distinction between HTTP POST and HTTP PUT calls. For this method you must use HTTP PUT. If you send a POST request, you would be making a brand new subprofile.

Supported parameters

You must use two different ways to pass data to this method; through the URL and the request body. You can pass the following parameters to the URL:

The fields parameter is required, to prevent overwriting all profiles in a database with a single API call. Only the subprofiles that match with the supplied fields are modified. You can find more information about this parameter in the article about this parameter.

PHP example

This PHP script demonstrates how you can use this API call. In this specific case we use the CustomerID field to find all subprofiles with value 4567 and update those subprofiles with the values in the body data.

JSON example

The following JSON demonstrates how to use the API method:

{
    "order_id": "12345",
    "order_date": "2023-01-01",
    "order_status": "completed"
}
// dependencies
require_once('CopernicaRestAPI.php');

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

// new values for the subprofile
$fields = array(
    'firstname' =>  'John',
    'lastname'  =>  'Doe',
    'email'     =>  'johndoe@example.com'
);

// the data for the call
$data = array(
    'fields'    =>  $fields,
);

// parameters
$parameters = array(
    'fields'    =>  array("customerid==4567"),
);

// do the call and print the result
print_r($api->put("collection/{$collectionID}/subprofiles", $data, $parameters));

The example above requires the CopernicaRestApi class.

More information