launchdarkly / api-client-python

LaunchDarkly API Client for Python
Other
5 stars 8 forks source link

Put_flag_settings issue #3

Closed liviadhalim closed 2 years ago

liviadhalim commented 4 years ago

Hi,

I was trying to enable a couple of flags that I have by running the command below

It seems to work for some. For the ones that do not work, I notice that they are temporary flags. Does it not work with temporary flags?

    def enableFeature(project_key, environment_key, flagKeys, userid):
        # create an instance of the API class
        pprint("Enabling feature toggles for feature {}".format(feature))
        api_instance = launchdarkly_api.UserSettingsApi(launchdarkly_api.ApiClient(configuration))
        project_key = project_key  # str | The project key, used to tie the flags together under one project so they can be managed together.
        environment_key = environment_key  # str | The environment key, used to tie together flag configuration and users under one environment so they can be managed together.
        user_key = userid  # str | The user's key.
        user_settings_body = launchdarkly_api.UserSettingsBody()  # UserSettingsBody |

        for key in flagKeys:
            pprint(key)
            try:
                # Specifically enable or disable a feature flag for a user based on their key.
                api_response = api_instance.get_user_flag_setting(project_key, environment_key, user_key, key)
                flagValue = api_response.value

                if (flagValue == False):
                    api_instance.put_flag_setting(project_key, environment_key, user_key, key, user_settings_body)
                    api_response = api_instance.get_user_flag_setting(project_key, environment_key, user_key, key)
                    flagValue = api_response.value
                    pprint(flagValue)
                    pprint("Flag {} for feature {} was turned on".format(key, feature))
                else:
                    pprint("Flag {} for feature {} is already turned on".format(key, feature))
            except ApiException as e:
                print("Exception when calling UserSettingsApi->put_flag_setting: %s\n" % e)
        pprint("Successfully enabled feature toggles for feature {}".format(feature))

Thanks! Livia

bwoskow-ld commented 4 years ago

Hi @liviadhalim,

This API should work for temporary flags just like permanent or other flags. Are you still running into this error? Can you provide the output from your "Exception when calling UserSettingsApi->put_flag_setting" print statement? I'm most interested in the value of e -- there's no need to include specific user or environment data in your response.

Cheers, Ben

jazanne commented 2 years ago

We have released our new OpenAPI v3 client. If you continue to have problems, don't hesitate to reopen the issue.