0

I was wondering if it was possible to create a custom endpoint in Marketing Cloud? I am in a position where an API call is being sent to MC but unfortunately MC only accepts email and we are sending a UUID as input.

Is it possible to use ampscript in the initial API request to replace the UUID with the respective email address from SF? Thanks!

2

I have built a number of custom endpoints using JSON code resources within Cloud Pages. You can send e.g. POST request to the URL of this code resource, and read all the data sent to it, using RequestParameter function.

From here, you can use regular Ampscript and/or SSJS to manipulate data in your data extensions, or basically perform any other function supported by the platform.

You can print the result as JSON, allowing the source system sending the request to identify whether the request was processed successfully or not.

It is important to state, this is NOT a real API with authentication, and whatever else is in place when looking at the native endpoints provided by SFMC. Hence appropriate measures should be taken when developing the code, as well as when distributing the endpoint URL.

If you need to send a triggered email, you can use this SSJS to send it:

function sendTSD(variableX,variableY,emailAddress,subKey) {
  var proxy = new Script.Util.WSProxy();
  var customerKey = "yourTriggeredEmail"; //key of your triggered send definition
  var name = "yourTriggeredEmail";

  var ts= {
         TriggeredSendDefinition: {CustomerKey: customerKey, Name: name}
         ,Subscribers: [ {
                EmailAddress: emailAddress
              , SubscriberKey: subKey
              , Attributes: [
                  {
                   Name: 'foo',
                    Value: variableX
                 },
                 {
                  Name: 'bar',
                  Value: variableY
                 }
              ]
          }]

      };

  var res = proxy.createItem("TriggeredSend", ts);

  return res;
}

To fetch the subscriber key prior to firing the code above, use LookupRows to look it up in a data extension. To pass variables from ampscript to SSJS, you will need to use the SSJS functions GetValue and SetValue.

6
  • Thanks alot Lukas, this is quite new to me - I have never had to do this, but I quickly went to cloud pages and clicked create code resource. It provided me JS code. Am I to write JS to create a custom endpoint? Ive done web dev in the past but never having to create a custom EP. – GS65 Jan 27 '20 at 10:44
  • Hi @GS65 - you don't provide information on what you exactly need to achieve in terms of integration. Should it triggere a journey? Or just update a data extension? I will strongly suggest you to familiarise yourself with SSJS and Ampscript basics, as providing complete solutions based on vague recommendations is outside of the scope of this site. – Lukas Lunow Jan 27 '20 at 10:48
  • Thanks Lukas, in our case it would be to trigger emails solely. I do have experience in javascript but SSJS is a new world that I have no experience in. I do know ampscript and was thinking of using the lookup function to replace with the code I need but setting up an endpoint is something new. I will google a guide on this but our goal is to send an API call to trigger an email. Thanks again – GS65 Jan 27 '20 at 11:00
  • Please see my updated answer, and don't forget to upvote/accept it for the benefit of the community. – Lukas Lunow Jan 27 '20 at 11:08
  • This is very helpful, thanks Lukas for your assistance! – GS65 Jan 27 '20 at 12:14

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.