0

I'm trying to implement a way of writing to a data extension (to be included as entry event in Journey Builder) directly from the HTML of a website.

As an example I have the following:

<html>
<body>

<p id="p1">Test</p>

<script>
var url = "https://mc.s7.exacttarget.com/cloud/v1/dataevents/key:660FD1E7-4BFE-48FE-930C-DC2BA53F7B4F/rowset";
var method = "POST";
var postData = "Some data";

var async = true;
var request = new XMLHttpRequest();
request.onload = function () {

   var status = request.status; // HTTP response status, e.g., 200 for "200 OK"
   var data = request.responseText; // Returned data, e.g., an HTML document.
}

request.open(method, url, async);

request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

// Actually sends the request to the server.
request.send(postData);

document.getElementById("p1").innerHTML = "Data:";

</script>

</body>
</html>  

I think I'm missing somewhere to put the requestToken reference. The idea is to have a website event trigger that some values (like Email, name, etc) should be inserted into a DE to be used in a Journey.

The way we initially intented was to have some sort of code (js or otherwise) trigger that a client left a shopping cart and then insert that contact into an Abadoned Cart journey but that does not seem feasible without heavy coding.

Any help would be greatly appreaciated!

4

It appears that you are attempting to make a client-side request from the user agent (web browser) to the Marketing Cloud REST API.

As you correctly identified, you will need to firstly obtain an access token using the OAuth credentials (client Id and Client Secret) that you obtained when creating your API Integration App in App Center.

However, if you intend to also perform this event client side (which is technically possible), then you are making a very serious security mistake. I would never make your OAuth credentials publicly available, and it's not really a sensible idea to include your access token in a client side script either (as it can be used for one hour).

You need to either use a server-side web framework (.NET, PHP, etc) to publish the page, or alternatively you could write a server-side middleware app to receive requests from an HTML form and proxy them to the Marketing Cloud API.

  • Thanks Elliot! We understand what you mean about the OAuth and will work on the best way to do that. Besides, how would you go about writing to a DE? the only method I have found would be using 'POST /dataeventsasync/key:{key}/rowset' But we need to write all the values without a keys object because we are creating users. Other method I think is POST /contacts, but we are writing to a DE, not a list, and according to the documentation it says: Creates a new contact with the specified information in the specified attribute groups. Ideas? – Esteban Alvarado Oct 7 '16 at 0:03
  • In the dataeventsasync method you refer to, the 'customer key' value in the URL parameter has nothing to do with the customer. This is the External Key of the Data Extension, which you can retrieve from the External Key field in the Properties tab of the Data Extension page. – Eliot Harper Oct 7 '16 at 3:53
1

You could try using Web Collect:

https://help.marketingcloud.com/en/documentation/exacttarget/subscribers/web_collect/

There is the option to add to a Data Extension too using "DEManager"

  • Thanks @C Carswell! Here's the thing: we are trying to get the information from a client that has left the shopping cart or made a purchase. The clients website triggers certain events whenever a customer leaves the cart at certain steps. Each of those events contains information about the client that we want to send to a data extension to be used in a Journey. – Esteban Alvarado Oct 7 '16 at 3:22
  • Ideally we'd trigger the Journey from the event on the website, but due to time constrains that is impossible., that is why we are looking for the fastest way to achieve that. And Im not sure Web Collect and DEManager would help. If there's a way to populate each field with the client information from a certain website event (for example Email: <input type="text" name="Email"><br />, then Im up for it! Thanks anyway! – Esteban Alvarado Oct 7 '16 at 3:22
0

You can use API event as an entry source. For that, you need to call API on whatever event you want such as when user submit a form.

Below is the sample JSON body of API request. { "ContactKey": "nikhilkhandare733@gmail.com", "EventDefinitionKey":"APIEvent-6a6c8900-2d96-1a72-fe74-271296219XXX", //This is event defination key that got generated when you drag and drop API event to journey builder "EstablishContactKey": true, "Data": {// These are fields of data extension "OrderId":"123456", "AccountId":"John Smith", "Email":"nikhilkhandare733@gmail.com", "FirstName":"nikhil", "LastName":"khandare", "OrderStatus":"Draft"

}

}

You need to submit this request to endpoint https://www.exacttargetapis.com/interaction/v1/events

Thank You! Nikhil

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.