editSettings
Otherwise, a new one is added.
Usage
// Initialize the client
var client = new CompositionClient(
new CompositionConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
);
// Call the API
var response = await client.PutCompositionRuleAsync(
"compositionID",
"rule-with-external-provider-source",
new CompositionRule
{
ObjectID = "rule-with-external-provider-source",
Conditions = new List<Condition>
{
new Condition { Anchoring = Enum.Parse<Anchoring>("Contains"), Pattern = "harry" },
},
Consequence = new CompositionRuleConsequence
{
Behavior = new CompositionBehavior(
new CompositionInjectionBehavior
{
Injection = new Injection
{
Main = new InjectionMain
{
Source = new InjectionMainSource(
new InjectionMainSearchSource
{
Search = new InjectionMainSearch { Index = "my-index" },
}
),
},
InjectedItems = new List<InjectionInjectedItem>
{
new InjectionInjectedItem
{
Key = "my-unique-external-provider-group-from-rule-key",
Source = new InjectedItemSource(
new InjectedItemExternalProviderSource
{
ExternalProvider = new InjectedItemExternalProvider
{
Index = "my-index",
ConfigurationID = "my-rmn-connection",
ConfigurationParams = new Dictionary<string, object>
{
{ "campaign_id", "summer-sale" },
},
Ordering = Enum.Parse<ExternalProviderOrdering>("ProviderDefined"),
},
}
),
Position = 0,
Length = 3,
},
},
},
}
),
},
}
);
// print the response
Console.WriteLine(response);
// Initialize the client
final client = CompositionClient(
appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');
// Call the API
final response = await client.putCompositionRule(
compositionID: "compositionID",
objectID: "rule-with-external-provider-source",
compositionRule: CompositionRule(
objectID: "rule-with-external-provider-source",
conditions: [
Condition(
anchoring: Anchoring.fromJson("contains"),
pattern: "harry",
),
],
consequence: CompositionRuleConsequence(
behavior: CompositionInjectionBehavior(
injection: Injection(
main: InjectionMain(
source: InjectionMainSearchSource(
search: InjectionMainSearch(
index: "my-index",
),
),
),
injectedItems: [
InjectionInjectedItem(
key: "my-unique-external-provider-group-from-rule-key",
source: InjectedItemExternalProviderSource(
externalProvider: InjectedItemExternalProvider(
index: "my-index",
configurationID: "my-rmn-connection",
configurationParams: {
'campaign_id': "summer-sale",
},
ordering:
ExternalProviderOrdering.fromJson("providerDefined"),
),
),
position: 0,
length: 3,
),
],
),
),
),
),
);
// print the response
print(response);
// Initialize the client
client, err := composition.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
// Call the API
response, err := client.PutCompositionRule(client.NewApiPutCompositionRuleRequest(
"compositionID", "rule-with-external-provider-source",
composition.NewEmptyCompositionRule().SetObjectID("rule-with-external-provider-source").SetConditions(
[]composition.Condition{
*composition.NewEmptyCondition().SetAnchoring(composition.Anchoring("contains")).SetPattern("harry"),
}).
SetConsequence(
composition.NewEmptyCompositionRuleConsequence().SetBehavior(composition.CompositionInjectionBehaviorAsCompositionBehavior(
composition.NewEmptyCompositionInjectionBehavior().SetInjection(
composition.NewEmptyInjection().SetMain(
composition.NewEmptyInjectionMain().SetSource(composition.InjectionMainSearchSourceAsInjectionMainSource(
composition.NewEmptyInjectionMainSearchSource().SetSearch(
composition.NewEmptyInjectionMainSearch().SetIndex("my-index"))))).SetInjectedItems(
[]composition.InjectionInjectedItem{
*composition.NewEmptyInjectionInjectedItem().SetKey("my-unique-external-provider-group-from-rule-key").SetSource(composition.InjectedItemExternalProviderSourceAsInjectedItemSource(
composition.NewEmptyInjectedItemExternalProviderSource().SetExternalProvider(
composition.NewEmptyInjectedItemExternalProvider().SetIndex("my-index").SetConfigurationID("my-rmn-connection").SetConfigurationParams(map[string]any{"campaign_id": "summer-sale"}).SetOrdering(composition.ExternalProviderOrdering("providerDefined"))))).SetPosition(0).SetLength(3),
}),
))))))
if err != nil {
// handle the eventual error
panic(err)
}
// print the response
print(response)
// Initialize the client
CompositionClient client = new CompositionClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
// Call the API
TaskIDResponse response = client.putCompositionRule(
"compositionID",
"rule-with-external-provider-source",
new CompositionRule()
.setObjectID("rule-with-external-provider-source")
.setConditions(Arrays.asList(new Condition().setAnchoring(Anchoring.CONTAINS).setPattern("harry")))
.setConsequence(
new CompositionRuleConsequence().setBehavior(
new CompositionInjectionBehavior().setInjection(
new Injection()
.setMain(
new InjectionMain().setSource(new InjectionMainSearchSource().setSearch(new InjectionMainSearch().setIndex("my-index")))
)
.setInjectedItems(
Arrays.asList(
new InjectionInjectedItem()
.setKey("my-unique-external-provider-group-from-rule-key")
.setSource(
new InjectedItemExternalProviderSource().setExternalProvider(
new InjectedItemExternalProvider()
.setIndex("my-index")
.setConfigurationID("my-rmn-connection")
.setConfigurationParams(
new HashMap() {
{
put("campaign_id", "summer-sale");
}
}
)
.setOrdering(ExternalProviderOrdering.PROVIDER_DEFINED)
)
)
.setPosition(0)
.setLength(3)
)
)
)
)
)
);
// print the response
System.out.println(response);
// Initialize the client
const client = compositionClient('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
const response = await client.putCompositionRule({
compositionID: 'compositionID',
objectID: 'rule-with-external-provider-source',
compositionRule: {
objectID: 'rule-with-external-provider-source',
conditions: [{ anchoring: 'contains', pattern: 'harry' }],
consequence: {
behavior: {
injection: {
main: { source: { search: { index: 'my-index' } } },
injectedItems: [
{
key: 'my-unique-external-provider-group-from-rule-key',
source: {
externalProvider: {
index: 'my-index',
configurationID: 'my-rmn-connection',
configurationParams: { campaign_id: 'summer-sale' },
ordering: 'providerDefined',
},
},
position: 0,
length: 3,
},
],
},
},
},
},
});
// print the response
console.log(response);
// Initialize the client
val client = CompositionClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
var response =
client.putCompositionRule(
compositionID = "compositionID",
objectID = "rule-with-external-provider-source",
compositionRule =
CompositionRule(
objectID = "rule-with-external-provider-source",
conditions =
listOf(
Condition(
anchoring = Anchoring.entries.first { it.value == "contains" },
pattern = "harry",
)
),
consequence =
CompositionRuleConsequence(
behavior =
CompositionInjectionBehavior(
injection =
Injection(
main =
InjectionMain(
source =
InjectionMainSearchSource(
search = InjectionMainSearch(index = "my-index")
)
),
injectedItems =
listOf(
InjectionInjectedItem(
key = "my-unique-external-provider-group-from-rule-key",
source =
InjectedItemExternalProviderSource(
externalProvider =
InjectedItemExternalProvider(
index = "my-index",
configurationID = "my-rmn-connection",
configurationParams =
buildJsonObject {
put("campaign_id", JsonPrimitive("summer-sale"))
},
ordering =
ExternalProviderOrdering.entries.first {
it.value == "providerDefined"
},
)
),
position = 0,
length = 3,
)
),
)
)
),
),
)
// print the response
println(response)
// Initialize the client
$client = CompositionClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
$response = $client->putCompositionRule(
'compositionID',
'rule-with-external-provider-source',
['objectID' => 'rule-with-external-provider-source',
'conditions' => [
['anchoring' => 'contains',
'pattern' => 'harry',
],
],
'consequence' => ['behavior' => ['injection' => ['main' => ['source' => ['search' => ['index' => 'my-index',
],
],
],
'injectedItems' => [
['key' => 'my-unique-external-provider-group-from-rule-key',
'source' => ['externalProvider' => ['index' => 'my-index',
'configurationID' => 'my-rmn-connection',
'configurationParams' => ['campaign_id' => 'summer-sale',
],
'ordering' => 'providerDefined',
],
],
'position' => 0,
'length' => 3,
],
],
],
],
],
],
);
// print the response
var_dump($response);
# Initialize the client
# In an asynchronous context, you can use CompositionClient instead, which exposes the exact same methods.
client = CompositionClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.put_composition_rule(
composition_id="compositionID",
object_id="rule-with-external-provider-source",
composition_rule={
"objectID": "rule-with-external-provider-source",
"conditions": [
{
"anchoring": "contains",
"pattern": "harry",
},
],
"consequence": {
"behavior": {
"injection": {
"main": {
"source": {
"search": {
"index": "my-index",
},
},
},
"injectedItems": [
{
"key": "my-unique-external-provider-group-from-rule-key",
"source": {
"externalProvider": {
"index": "my-index",
"configurationID": "my-rmn-connection",
"configurationParams": {
"campaign_id": "summer-sale",
},
"ordering": "providerDefined",
},
},
"position": 0,
"length": 3,
},
],
},
},
},
},
)
# print the response
print(response)
# Initialize the client
client = Algolia::CompositionClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.put_composition_rule(
"compositionID",
"rule-with-external-provider-source",
Algolia::Composition::CompositionRule.new(
algolia_object_id: "rule-with-external-provider-source",
conditions: [Algolia::Composition::Condition.new(anchoring: "contains", pattern: "harry")],
consequence: Algolia::Composition::CompositionRuleConsequence.new(
behavior: Algolia::Composition::CompositionInjectionBehavior.new(
injection: Algolia::Composition::Injection.new(
main: Algolia::Composition::InjectionMain.new(
source: Algolia::Composition::InjectionMainSearchSource.new(
search: Algolia::Composition::InjectionMainSearch.new(index: "my-index")
)
),
injected_items: [
Algolia::Composition::InjectionInjectedItem.new(
key: "my-unique-external-provider-group-from-rule-key",
source: Algolia::Composition::InjectedItemExternalProviderSource.new(
external_provider: Algolia::Composition::InjectedItemExternalProvider.new(
index: "my-index",
configuration_id: "my-rmn-connection",
configuration_params: {campaign_id: "summer-sale"},
ordering: "providerDefined"
)
),
position: 0,
length: 3
)
]
)
)
)
)
)
# print the response
puts(response)
// Initialize the client
val client = CompositionClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
val response = Await.result(
client.putCompositionRule(
compositionID = "compositionID",
objectID = "rule-with-external-provider-source",
compositionRule = CompositionRule(
objectID = "rule-with-external-provider-source",
conditions = Some(
Seq(
Condition(
anchoring = Some(Anchoring.withName("contains")),
pattern = Some("harry")
)
)
),
consequence = CompositionRuleConsequence(
behavior = CompositionInjectionBehavior(
injection = Injection(
main = InjectionMain(
source = Some(
InjectionMainSearchSource(
search = InjectionMainSearch(
index = "my-index"
)
)
)
),
injectedItems = Some(
Seq(
InjectionInjectedItem(
key = "my-unique-external-provider-group-from-rule-key",
source = InjectedItemExternalProviderSource(
externalProvider = InjectedItemExternalProvider(
index = "my-index",
configurationID = "my-rmn-connection",
configurationParams = Some(Map("campaign_id" -> "summer-sale")),
ordering = Some(ExternalProviderOrdering.withName("providerDefined"))
)
),
position = 0,
length = 3
)
)
)
)
)
)
)
),
Duration(100, "sec")
)
// print the response
println(response)
// Initialize the client
let client = try CompositionClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")
// Call the API
let response = try await client.putCompositionRule(
compositionID: "compositionID",
objectID: "rule-with-external-provider-source",
compositionRule: CompositionRule(
objectID: "rule-with-external-provider-source",
conditions: [CompositionCondition(pattern: "harry", anchoring: CompositionAnchoring.contains)],
consequence: CompositionRuleConsequence(behavior: CompositionBehavior
.compositionInjectionBehavior(CompositionInjectionBehavior(injection: Injection(
main: InjectionMain(source: InjectionMainSource
.injectionMainSearchSource(
InjectionMainSearchSource(search: InjectionMainSearch(index: "my-index"))
)),
injectedItems: [InjectionInjectedItem(
key: "my-unique-external-provider-group-from-rule-key",
source: InjectedItemSource
.injectedItemExternalProviderSource(
InjectedItemExternalProviderSource(externalProvider: InjectedItemExternalProvider(
index: "my-index",
configurationID: "my-rmn-connection",
configurationParams: ["campaign_id": AnyCodable("summer-sale")],
ordering: ExternalProviderOrdering.providerDefined
))
),
position: 0,
length: 3
)]
))))
)
)
// print the response
print(response)
See the full API reference
For more details about input parameters
and response fields.