novu-python icon indicating copy to clipboard operation
novu-python copied to clipboard

LayoutApi alway returns HTTP error 400

Open gjae opened this issue 1 year ago • 1 comments

I'm trying creates an layout using Layout Api always returns error 400. Current implementation:

body = "html readed from a file, contains {{{body}}}"
variables = [
    {"type": "String", "name": "first_name", "required": False, "defValue": ""},
    {"type": "String", "name": "lastname", "required": False, "defValue": ""},
    {"type": "String", "name": "email", "required": False, "defValue": ""},
    {"type": "String", "name": "cellphone", "required": False, "defValue": ""},
    {"type": "String", "name": "url", "required": False, "defValue": ""},
    {"type": "String", "name": "path", "required": False, "defValue": ""},
    {"type": "String", "name": "uuid", "required": False, "defValue": ""},
    {"type": "String", "name": "id", "required": False, "defValue": ""},
    {"type": "String", "name": "instagram", "required": False, "defValue": ""},
    {"type": "String", "name": "facebook", "required": False, "defValue": ""},
]
variables_dto = []
for variable in variables:
    variables_dto.append(LayoutVariableDto(
        name=variable["name"],
        type=TemplateVariableTypeEnum.STRING,
    ))


new_layout = LayoutDto(
    name=template_name,
    description="mail templates",
    content=body,
    is_default=False,
    variables=variables_dto,
)
response = None
try:
    response = LayoutApi(settings.NOVU_DOMAIN, settings.NOVU_API_KEY).create(new_layout)
    NotificationTemplate.objects.create(
        name=template_name,
        local_identifier=identifier,
        novu_id=response._id,
        variables=json.dumps(variables)
    )
except Exception as e:
    print(response, e)
    raise e

I need automate the layouts creation

image

  • Novu version: last version (using api.novu.co)
  • Python version: 3.10.13
  • Novu-python version: 1.14.0

Additional context I'm using django, the api key it's a environment variable

gjae avatar Mar 19 '24 05:03 gjae