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

Can't send addValuesToClause operation via api-client #10

Open
michaelk-redis opened this issue Jan 15, 2024 · 1 comment
Open

Can't send addValuesToClause operation via api-client #10

michaelk-redis opened this issue Jan 15, 2024 · 1 comment

Comments

@michaelk-redis
Copy link

Hey,

I know this is auto generated client, but hopefully you would have a solution.

When i use the api-client-typescript package, and try to send a .patchFeatureFlag() with a payload example:

    "environmentKey": "environment-key-123abc",
    "instructions": [{
        "kind": "addValuesToClause",
        "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29",
        "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
        "values": ["beta_testers"]
    }]
}

There are 2 problems:

  1. type PatchOperation only supports properties: op, path and value, so there is a TS compile error.
  2. Even after getting over the compile error, i've debugged and noticed that the request being sent with the following payload:
    "patch": [
        {
            "environmentKey": "environment-key-123abc",
            "instructions": [
                {
                    "kind": "addValuesToClause",
                    "ruleId": "a902ef4a-2faf-4eaf-88e1-ecc356708a29,
                    "clauseId": "10a58772-3121-400f-846b-b8a04e8944ed",
                    "values": [
                        "please-work"
                    ]
                }
            ]
        }
    ]
}

And the response from the REST API is 400 Error

    "code": "invalid_patch",
    "message": "must have at least one instruction"
}

Please advise, is there a way to use all the different patch operations via the client?

@bwoskow-ld
Copy link
Member

Hi @michaelk-redis ,

While our REST API endpoint supports JSON patch and semantic patch protocols for updating your feature flags, our API client libraries only support JSON patch. This is due to an issue with the generator where some of the client libraries aren't able to handle the flexibility of supporting two distinct formats for a common API endpoint.

The format you described with instructions is our semantic patch protocol. This is incompatible with how the library works.

Instead, with JSON patch, you'll specify an op, path, and value - in line with what you mentioned from the PatchOperation type. Search for Using JSON patches on a feature flag on the API doc to learn more about how to structure these requests.

If you don't want to use JSON patch to update your flags and you instead want to use semantic patch, you'll need to hand-craft those HTTP requests outside of the API client library.

Cheers,
Ben

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

No branches or pull requests

2 participants