0

I'm trying to communicate with an SMTP API from my IOS application. The API uses HTTPS requests, however, I'm unsure how to make one within Swift. The application exemplifies the following cURL request as a way of communicating with the API:

curl --request POST \
  --url https://api.sendinblue.com/v3/smtp/email \
  --header 'accept: application/json' \
  --header 'api-key:YOUR_API_KEY' \
  --header 'content-type: application/json' \
  --data '{  
   "sender":{  
      "name":"Sender Alex",
      "email":"senderalex@example.com"
   },
   "to":[  
      {  
         "email":"testmail@example.com",
         "name":"John Doe"
      }
   ],
   "subject":"Hello world",
   "htmlContent":"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Sendinblue.</p></body></html>"
}'

How can I make this request from my code project?

Any help would be greatly appreciated!

James
  • 127
  • 11
  • What do you find if you ask Google, Yahoo! or whatever about 'Swift curl use'? – El Tomato Jul 30 '21 at 02:18
  • 1
    Does this answer your question? [How to perform a curl request in swift?](https://stackoverflow.com/questions/52032108/how-to-perform-a-curl-request-in-swift) – Phil Dukhov Jul 30 '21 at 02:36
  • @Philip that answers it except I'm unsure how to format my payload data in the way that they do in that example. The payload I need to send has nested properties so I'm a bit confused – James Jul 30 '21 at 02:53
  • in swift you can do like this: `"some text: \(variable)"`, also you probably wanna use a dictionary here, like `["sender": ["email": variable1], "subject": variable2]`, so check out [Convert Dictionary to JSON in Swift](https://stackoverflow.com/a/29625483/3585796) – Phil Dukhov Jul 30 '21 at 02:59

0 Answers0