matthiasgomolka / simfinapi

Makes 'SimFin' data (https://simfin.com/) easily accessible in R.
19 stars 4 forks source link

Must comply to pattern error when setting enviroment variable #16

Closed MislavSag closed 3 years ago

MislavSag commented 3 years ago

When I want to set api key as environment variable:

simfinapi::sfa_set_api_key(env_var = "8qk9Xc9scFc0R...")

I get an error:

Error in simfinapi::sfa_set_api_key(env_var = "8qk9Xc9scFc0R...") : 
  Assertion on 'sfa_api_key' failed: Must comply to pattern '^[[:alnum:]]{32}$'.
matthiasgomolka commented 3 years ago

As far as I know, all SimFin API keys have a length of 32 characters and may contain characters and numbers. This is checked before setting the API key.

In your example, the API key contains ... which is not allowed. This is why you get the error.

I suspect, your real API key looks different. Please report if it's length is not 32 or if it contains other elements than characters or numbers (and which).

MislavSag commented 3 years ago

My API key is OK (it contains characters and numbers). I have added ... to hide my API key.

I see there is a code:

 if (env_var_specified) {
    options(sfa_api_key = Sys.getenv(env_var))
  }

So I have to provide environment variable name that contains my api key?

matthiasgomolka commented 3 years ago

Sorry, I can't reproduce your problem in the recent dev version. Do you really get the exact same error as shown above? Because this error only occurs if your API key's length differs from 32 or if it contains other elements than characters and/or numbers. You can test this using grepl('^[[:alnum:]]{32}$', "InsertYourApiKey").


You do not have to provide an environment variable name (even though I would recommend this, because then you don't have to insert your API key in your script file). For details see ?sfa_set_api_key, especially the examples:

# set API key directly
sfa_set_api_key(api_key = "YourApiKey")

# set API key via environment variable
# (this assumes you already created an environment variable called
# 'SIMFIN_API_KEY' which contains your API key)
sfa_set_api_key(env_var = "SIMFIN_API_KEY")
matthiasgomolka commented 3 years ago

@MislavSag, could you solve your problem?

MislavSag commented 3 years ago

No, I just use API inside function every time. But I am sure the problem is not in API string. I can send you my API key by e-mail.

matthiasgomolka commented 3 years ago

No, you should never pass your API key to someone else. But it would be helpful if you would provide a real reprex, including your session info.

Have you checked your API key as decribed above?

grepl('^[[:alnum:]]{32}$', "InsertYourApiKey")

This should return TRUE. If not, please provide an example of your API key where you replace all digits.

MislavSag commented 3 years ago

That returns TRUE, I tried that right after I saw there is an error.

matthiasgomolka commented 3 years ago

This should return TRUE. If not, please provide an example of your API key where you replace all digits.

Closing the issue since I don't have the information to reproduce the error.