1

I'm trying to fire an api event (https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/postEvent.htm) with fuelsdk-node rest (https://github.com/salesforce-marketingcloud/FuelSDK-Node-REST)

This is the code:

var apiTrigger = function(apiKey, email, firstName, lastName) {
    var options = {
      auth: {
          // options you want passed when Fuel Auth is initialized
          clientId: 'xxxx',
          clientSecret: 'xxxx'
      },
      origin: 'https://www.exacttargetapis.com',
      method: 'POST',
      uri: '/interaction/v1/events',
      headers: {
        "ContactKey":email,
        'EventDefinitionKey':apiKey,
        "EstablishContactKey": true,
        "Data": 
          {
            "first_name":firstName,
            "last_name":lastName,
            "email":email
          }
       }
    };
    var RestClient = new FuelRest(options);
    RestClient
        .post(options)
        .then(function(response) {
            console.log(response.body);
        })
        .catch(function(err) {});
}

I get this error in the response:

{ message: 'Runtime Error. Retry this action. Contact Global Support if the issue persists', errorcode: 30000, documentation: '' }

Has anyone been able to do this with the this node package? If you have a raw code version (with oauth authentication) that would be great.

Just looking to fire an api event to trigger a journey with the payload included using node.js.

  • If my answer helped, please mark it as accepted so others can easily see this has been resolved. Thank you! – Markus Slabina Sep 5 '17 at 17:29
1

The problem is, you are putting the data that needs to be supplied in the body-part of the request in the header instead and are completely omitting the body. Furthermore you mix the setup-options of the library with the request-options/data as you are using the same object for initialising the library and sending the POST-request.

I successfully triggered a journey builder API-event using the following code:

const FuelRest = require('fuel-rest');

const restClient = new FuelRest({
    auth: {
        clientId: 'YOUR_CLIENT_ID',
        clientSecret: 'YOUR_CLIENT_SECRET'
    }
});

const triggerEntryEventRequest = {
    uri: 'https://www.exacttargetapis.com/interaction/v1/events',
    json: true,
    method: 'POST',
    body: {
        ContactKey: 'YOUR_CONTACT_KEY',
        EventDefinitionKey: 'YOUR_APIEvent_KEY',
        data: {
            'Field1': 'Value',
            'Field2': 'Value'
        }
    }
};

restClient.post(triggerEntryEventRequest, (err, res) => {
    if (err)    console.error(err);
    else        console.log(res);
});
  • Thanks. I got it to work without the fuel-rest package, but this is good to know. – findev Sep 23 '17 at 15:40

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.