I'm trying to call the WordReplacement
API v3 with the replace
action. The APIv3 Explorer tells me the right PHP syntax is as show below. (I previously called WordReplacement
get
to get the correct id
value.)
$result = civicrm_api3('WordReplacement', 'replace', [
'id' => 2,
'find_word' => "Contribute",
'replace_word' => "Give Now",
'domain_id' => "my-domain-name-here",
'match_type' => "exactMatch",
'is_active' => 1
]);
But executing that in the API Explorer returns the error:
{
"is_error": 1,
"error_message": "Mandatory key(s) missing from params array: values"
}
I figured out this is calling the "generic" replace
API, and by digging through the API examples (for Email
and UFField
), it appears the correct syntax is something like:
$result = civicrm_api3('WordReplacement', 'replace', [
'some_key' => 'some_value',
'values' => [
'id' => 2, // maybe this ID isn't needed here?
'find_word' => "Contribute",
'replace_word' => "Give Soon",
'domain_id' => "my-domain-name-here",
'match_type' => "exactMatch",
'is_active' => 1
]
]);
I tried a few different guesses for some_key
and some_value
(and also tried omitting those entirely), but always got a new error Type error: Argument 3 passed to civicrm_api() must be of the type array, null given, called in /longpathgoeshere/wordpress/wp-content/plugins/civicrm/civicrm/api/v3/utils.php on line 1813
.
I also looked at some of the API definition files like civicrm\civicrm\api\v3\UFField.php
, Email.php
and WordReplacement.php
, as well as the API getfields
output, but nothing helped me to infer what the correct syntax should be. So I'd also be interested in hints on how to understand and learn from those as a developer.
I'm running WordPress v.5.4.4 and Civi v.5.35.1.