Skip to content

Commit

Permalink
Brevo: API to create companies (siae)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Feb 22, 2024
1 parent 5610404 commit 55d6ebf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@
"from lemarche.utils import constants",
"from lemarche.siaes import constants as siae_constants",
"from lemarche.tenders import constants as tender_constants",
"from lemarche.utils.apis import api_brevo, api_mailjet",
]
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"

Expand Down
24 changes: 24 additions & 0 deletions lemarche/utils/apis/api_brevo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from huey.contrib.djhuey import task
from sib_api_v3_sdk.rest import ApiException

from lemarche.siaes.models import Siae
from lemarche.users.models import User
from lemarche.utils.urls import get_admin_url_object, get_share_url_object


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -65,6 +67,28 @@ def remove_contact_from_list(user: User, list_id: int):
logger.error("Exception when calling Brevo->ContactsApi->remove_contact_from_list: %s\n" % e)


def create_company(siae: Siae):
api_client = get_api_client()
api_instance = sib_api_v3_sdk.CompaniesApi(api_client)
new_company = sib_api_v3_sdk.Body(
name=siae.name,
attributes={
"id": siae.id,
"siae": True,
"kind": siae.kind,
"domain": siae.website,
"link_app": get_share_url_object(siae),
"link_admin": get_admin_url_object(siae),
},
)

try:
api_response = api_instance.companies_post(new_company)
logger.info("Succes Brevo->CompaniesApi->create_company: %s\n" % api_response)
except ApiException as e:
logger.error("Exception when calling Brevo->CompaniesApi->create_company: %s\n" % e)


@task()
def send_transactional_email_with_template(
template_id: int,
Expand Down

0 comments on commit 55d6ebf

Please sign in to comment.