|
| 1 | +/** |
| 2 | + * Sinch Java Snippet |
| 3 | + * |
| 4 | + * <p>This snippet is available at https://github.com/sinch/sinch-sdk-java-snippets |
| 5 | + * |
| 6 | + * <p>See https://github.com/sinch/sinch-sdk-java-snippets/blob/main/README.md for details |
| 7 | + */ |
| 8 | +package mailgun.templates; |
| 9 | + |
| 10 | +import com.sinch.sdk.SinchClient; |
| 11 | +import com.sinch.sdk.domains.mailgun.api.v1.TemplatesService; |
| 12 | +import com.sinch.sdk.domains.mailgun.models.v1.templates.VersionDetails; |
| 13 | +import com.sinch.sdk.domains.mailgun.models.v1.templates.request.CreateVersionRequest; |
| 14 | +import com.sinch.sdk.models.Configuration; |
| 15 | +import com.sinch.sdk.models.MailgunRegion; |
| 16 | +import java.util.logging.Logger; |
| 17 | +import utils.Settings; |
| 18 | + |
| 19 | +public class CreateVersion { |
| 20 | + |
| 21 | + private static final Logger LOGGER = Logger.getLogger(CreateVersion.class.getName()); |
| 22 | + |
| 23 | + public static void main(String[] args) { |
| 24 | + |
| 25 | + String mailgunApiKey = Settings.getMailgunApiKey().orElse("MY_MAILGUN_API_KEY"); |
| 26 | + String mailgunRegion = Settings.getMailgunRegion().orElse("MY_MAILGUN_REGION"); |
| 27 | + |
| 28 | + String mailgunDomain = "A_MAILGUN_DOMAIN"; |
| 29 | + String mailgunTemplateName = "A_TEMPLATE_NAME"; |
| 30 | + String mailgunTemplateVersionName = "A_TEMPLATE_VERSION_NAME"; |
| 31 | + |
| 32 | + Configuration configuration = |
| 33 | + Configuration.builder() |
| 34 | + .setMailgunApiKey(mailgunApiKey) |
| 35 | + .setMailgunRegion(MailgunRegion.from(mailgunRegion)) |
| 36 | + .build(); |
| 37 | + |
| 38 | + SinchClient client = new SinchClient(configuration); |
| 39 | + |
| 40 | + TemplatesService templatesService = client.mailgun().v1().templates(); |
| 41 | + |
| 42 | + LOGGER.info("Create a template's version"); |
| 43 | + |
| 44 | + CreateVersionRequest request = |
| 45 | + CreateVersionRequest.builder() |
| 46 | + .setTemplate("<p>{{firstname}} {{lastname}}</p>") |
| 47 | + .setTag(mailgunTemplateVersionName) |
| 48 | + .build(); |
| 49 | + |
| 50 | + VersionDetails value = |
| 51 | + templatesService.createVersion(mailgunDomain, mailgunTemplateName, request); |
| 52 | + |
| 53 | + LOGGER.info("Response:" + value); |
| 54 | + } |
| 55 | +} |
0 commit comments