launchdarkly/api-client-typescript

Can't send addValuesToClause operation via api-client

michaelk-redis opened this issue · 1 comments

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?

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