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.

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

1 Answer 1

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);
});
1
  • Thanks. I got it to work without the fuel-rest package, but this is good to know.
    – Findev
    Sep 23, 2017 at 15:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .