pythondjangosendinblue

How do I automate this sendinblue api?


Trying to automate the adding of contacts to sendinblue's api. The example given on their site shows adding a email and then adding it to a list in your account.

I have tried fstrings and .format(email, industry, role) but for some reason it keeps throwing back errors.

Heres what their website shows which works.

import requests

url = "https://api.sendinblue.com/v3/contacts"

payload = "{\"email\":\"someonesEmail97@gmail.com\",\"listIds\":[1,4],\"updateEnabled\":false}"
headers = {
    'accept': "application/json",
    'content-type': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers

Here's what I tried

import requests

url = "https://api.sendinblue.com/v3/contacts"

payload = "{\"email\":\f"{email}"\",\"listIds\":[f"{industry}",f"{role}"],\"updateEnabled\":false}"
headers = {
    'accept': "application/json",
    'content-type': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

I want this in the signup part of my site so it will grab their email thats been authenticated and add it to the appropriate list that I have set up. But what I get back from using fstrings is invalid syntax in the terminal pointing to the email field. I then tried .format and that didn't show any errors on the terminal but on the webpage I got this error back


payload = "{\"email\":\{}\",\"listIds\":[{},{}],\"updateEnabled\":false}".format(email, industry, role)

KeyError at /accounts/signup/activate/ "'email'" points to line that the payload is on.

What am I missing? Thanks for reading


Solution

  • what I get back from using fstrings is invalid syntax in the terminal pointing to the email field

    That's because you have quote mismatches, and you tried to create the f-string(s) in a weird, not valid way.

    Try this:

    payload = f'{{"email":"{email}","listIds":[{industry},{role}],"updateEnabled":false}}'