<@U04UQ68083H> when setting up the sms courier ser...
# ory-copilot
e
@chilly-king-10285 when setting up the sms courier service in kratos config, why do we need to base64 the body request and what’s in the body request
b
A message from kapa.ai
When configuring the SMS courier service in Ory Kratos, the body of the HTTP request is often base64-encoded because the configuration expects the body template to be provided as a base64-encoded Jsonnet function. This approach ensures that the template content is safely and unambiguously included in the YAML or JSON configuration files, avoiding issues with special characters, formatting, or line breaks that could otherwise break the configuration syntax. What's in the body request? The body is a Jsonnet template that defines the payload sent to your SMS provider. For example, for Twilio, the decoded body might look like this:
Copy code
jsonnet function(ctx) {     To: ctx.recipient,     Body: ctx.body,   }
-
ctx.recipient
is the phone number of the user. -
ctx.body
is the message content (such as a verification or login code). The template can access other variables as well, such as
template_type
and
template_data
, depending on the type of message being sent. The base64 encoding is required for the configuration to accept the template, and only base64-encoded templates are supported in Ory Network and most production setups for security and compatibility reasons [Send SMS to your users](https://www.ory.sh/docs/kratos/emails-sms/sending-sms). Example configuration snippet:
Copy code
yaml courier:   channels:     - id: sms       type: http       request_config:         url: <https://api.twilio.com/2010-04-01/Accounts/AXXXXXXXXXXXXXX/Messages.json>         method: POST         body: base64://<base64-encoded-Jsonnet-template>         headers:           Content-Type: application/x-www-form-urlencoded         auth:           type: basic_auth           config:             user: <your-username>             password: <your-password>
You can find more details and examples in the official documentation [Send SMS to your users](https://www.ory.sh/docs/kratos/emails-sms/sending-sms).