[SalesForce] How to start sending an email from SFMC via external API?

We're currently looking into sending a welcome email from SFMC. I know this is possible but I don't know where to even start doing this. I'm fairly new to APIs in general, the most I have done so far is send an API call to our Events system from SFMC using server-side javascript to fill a data extension which we could then send emails to, and most of this was written from scratch by a consultant we were working with.

Ideally, our events system would send an API call to SFMC every time someone registers for an event, and this would trigger an email just to this one person.

Can someone give me an indication of what I need to set up for this – I've created a User-Intiated send, but I'm not even sure if this is the right way.

I'd also like to know if there's an easy way to test this – our new events platform is still under development so in the meantime I would like to be able to test sending the call from elsewhere, such as Postman.

Got this far with Postman – getting an Access Token

enter image description here

Best Answer

You need to create a triggered send definition and send a post-request to the REST-API. There is very good documentation on this, that you can find here:

Creating a triggered send:

In order to create a triggered send definition you need to perform the following steps in Email Studio:

  1. Click Interactions
  2. Click Messages
  3. Click Email
  4. Click Triggered
  5. Click Create
  6. Create Triggered Send
  7. Complete Properties (described in Create a Triggered Email Message Interaction)

Sending the triggered email using the REST-API

The call to the REST-API could look like this in the example below. The URL you post the request to needs to be adapted, as cust_key needs to be replaced by the customer/external key of your triggered send definition (the one you created using the explanation in the triggered emails guide.

Before you can initiate that request, you need to get an API key/secret using App Center, as this is necessary for obtaining the access token, that needs to be sent in the header of your subsequent requests (the one triggering the email send for example). These steps are described in the following documentation articles:

The access token retrieval can be handled by the SDK you use for making the requests. This depends on the setup you have (programming language, etc.). These are available for C#, PHP, Node.js, Java, etc. and are listed in the documentation article "Introduction to SDKs".

Request-Header:

Host: https://www.exacttargetapis.com
POST /messaging/v1/messageDefinitionSends/key:cust_key/send
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN

Request-Body:

{
    "From": {
        "Address": "code@exacttarget.com",
        "Name": "Code@"
    },
    "To": {
        "Address": "example@example.com",
        "SubscriberKey": "example@example.com",
        "ContactAttributes": {
            "SubscriberAttributes": {
                "Region": "West",
                "City": "Indianapolis",
                "State": "IN"
            }
        }
    },
    "OPTIONS": {
        "RequestType": "ASYNC"
    }
}
Related Topic