0

I have installed SparkPost on heroku. The issue is that I cannot find any of the settings for SparkPost either to conect with domain or use the API. The easier route seems to install the sparkpost package with pip, but using the documentation, I cannot pull in the API either with:

 sp = SparkPost()

or

sp = SparkPost(os.environ['API_KEY_SPARKPOST'])

The former gives the following error:

SparkPostException: No API key. Improve message.

and the latter, cannot find any environment variable. I had a search, I don't see any environment variables that are related to SparkPost. Not do I find any API option in the control panel with which to find one.

davidism
  • 121,510
  • 29
  • 395
  • 339
disruptive
  • 5,687
  • 15
  • 71
  • 135

2 Answers2

2

for the Heroku add-on the environment variable is called SPARKPOST_API_KEY and that is what gets used by default. Assuming you're running this locally, the problem in the first example is that you probably don't have SPARKPOST_API_KEY in your environment. When you run heroku local it will load up variables in a file called .env in your project's root. You'll want to add that by doing something like this:

heroku config:get SPARKPOST_API_KEY -s >> .env

Your second example is exactly what the python-sparkpost library does under the hood, but the name of the var is SPARKPOST_API_KEY.

You can see a list of all the env vars available for the SparkPost add-on here: https://devcenter.heroku.com/articles/sparkpost#provisioning-the-add-on. You can also run heroku config to see all of your env vars from the command-line.

richleland
  • 1,442
  • 9
  • 13
  • 1
    If you'd like to chat real-time about this or any other issues, feel free to reach out to us directly on Slack too - http://slack.sparkpost.com. – richleland Feb 28 '16 at 21:28
  • Thanks - there was probably more than one question cobbled together. Is there also a way to get the API from front-end. I saw some screenshots, has the UX changed? – disruptive Mar 01 '16 at 11:54
  • You can only see the API key on creation. If you go to https://app.sparkpost.com/account/credentials you can create new keys there - upon creation it'll show you the full key for copying. – richleland Mar 01 '16 at 17:52
1

When no arguments are supplied the SparkPost object will be created using the API key stored in the environment variable SPARKPOST_API_KEY.

To set environment variables in heroku you can use the following heroku toolbelt command:

heroku config:set SPARKPOST_API_KEY=<your-key-here>
orval
  • 97
  • 4