Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try and add rules #87

Closed
wants to merge 1 commit into from
Closed

Conversation

mosheeshel
Copy link

No description provided.

@vlymar
Copy link

vlymar commented May 14, 2021

Hi @mosheeshel, thanks for submitting a PR. It looks like you're trying to modify the openapi spec for segment creation to allow for including rules along with the initial POST request. Our segment creation API doesn't allow that. You have to create the segment, then PATCH the rules in.

Did I accurately understand your intent? Is there something else we can do to assist you? If not, I'll close this PR next week (feel free to close it before then).

@mosheeshel
Copy link
Author

@vlymar that makes sense. thanks.
closing this PR, but would appreciate an example of using the PatchOperation for updating UserSegment rules - I now see the patch operation supports multiple PatchOperation object, but the expected JSON structure is not really documented anywhere.

@mosheeshel mosheeshel closed this May 15, 2021
@mosheeshel mosheeshel deleted the patch-1 branch May 15, 2021 20:17
@bjlagman12
Copy link

Hi @mosheeshel, did you want an example using the API, or of using the open-api?

@mosheeshel
Copy link
Author

@bjlagman12 Looking for example/docs on using the patchSegment API to add a user rule to a segment (under /rules), in general what values will the PatchOperation accept and how to use it to manipulate a Segment to add/remove rules, tags, etc.
Also the same for Flags - I understand that it should be some path in the object representation of the entity, but it's not clear what the status is, and what operations are supported for each entity. The documentation (open api) shows only "raw body" (a known issue when the field is very dynamic/generic). And I could find no examples anywhere in your docs.
I'm using the Java API Client SDK, but pure JSON examples would be fine as well.

@bjlagman12
Copy link

Hey @mosheeshel below are some examples for patch operations for adding a user or rules to a segment. As mentioned above its important to create a segment then update that segment.

add rules to segment

{
    "patch":[
        {
            "op":"add",
            "path":"/rules/0",
            "value":{
                "clauses":[
                    {
                        "attribute":"Avon",
                        "op":"in",
                        "values":["24/7"],
                        "negate":false
                    }
                ]
            }
        },
        {
            "op":"add",
            "path":"/rules/1",
            "value":{
                "clauses":[
                    {
                        "attribute":"programming",
                        "op":"in",
                        "values":["Director","Product"],
                        "negate":false
                    }
                ]
            }
        }
    ]
}

replace rules in segment

{
    "patch":[
        {
            "op":"replace",
            "path":"/rules/0/clauses/0/attribute",
            "value":"Ouguiya"
        },
        {
            "op":"add",
            "path":"/rules/0/clauses/0/values/1",
            "value":"Intelligent"
        },
        {
            "op":"add",
            "path":"/rules/0/clauses/0/values/2",
            "value":179989888
        }
    ]
}

delete rules in segment

{
    "patch":[
        {
            "op":"remove",
            "path":"/rules/1"
        }
    ]
}

add user

[
    {
        "op": "add",
        "path": "/included/0",
        "value": "user1"
    },
    {
        "op": "add",
        "path": "/included/1",
        "value": "user2"
    }
]

Please refer to the API docs for information regarding updating a flag to add/ remove users and rules to a feature flag. The docs do a great job explaining the required parameters for successfully updating a featuring flag. Below is a simple example of adding users.

{
    "environmentKey":"production",
    "instructions":[
        {
            "kind":"addUserTargets",
            "values":["0002129c-86bb-4347-9447-a2a249feeb85"],
            "variationId":"64758432-d731-44a3-b915-93e02b8a8a73"
        }
    ]
}

@mosheeshel
Copy link
Author

This helped me build a working API client, nothing major, check it out - I don't know how much usage this API gets, but I assume anybody who wants to, needs to know the values and options here...
https://gist.github.com/mosheeshel/188214e51022a50d249898bd1309ad10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants