sfmc

node v10.24.1
version: 17.0.1
endpointsharetweet
const express = require('express') const bodyParser = require('body-parser') const app = express() const port = 3000 const request = require('request'); const fs = require('fs'); let sendResponse = ""; // Middleware to parse JSON bodies app.use(bodyParser.json()); // Endpoint to handle POST requests from Marketing Cloud app.post('/execute', (req, res) => { // Extract the inArguments from the request body const inArguments = req.body.inArguments; if (inArguments && Array.isArray(inArguments)) { // Process each inArgument inArguments.forEach(argument => { // Do something with each inArgument console.log('Received inArgument:', argument); fs.writeFileSync('https://testsale54321.000webhostapp.com/SMSfile/SMSin.txt', argument); }); //var sendResponse = ""; //call mulesoft SMS var externalUrl = "https://sunrise-campaign-eapi-v1-t04-z8mtul.djk77v.deu-c1.eu1.cloudhub.io/api/sms"; var headerdata = { "content-type":"application/json", "client_id":"a5deff7c680c4b96b2eee4a6e2e58df0", "client_secret":"746D3a6A1e994B9490834a91119cbC4D"} ; var payload = { "id": "28e882b4-21ee-4765-ab34-e762ac029bd5", "targetSystemId": "ZXCV-QWER-DSAA", "originatorSystemId": "SAJS-QERT-UIOP", "status": "SUBMITED", "from": "Sunrise", "receipt": false, "validFor": { "time": 10086, "unit": "DAY" }, "configurationId": "443", "recipientText": [ { "to": [ "0767770001" ], "text": "Welcome to Sunrise! Amazing things will happen." } ], "messageOptions": { "sendAt": "2015-12-17T00:00:00Z", "sendBetween": { "start": "2015-12-15T00:00:00Z", "end": "2015-12-17T00:00:00Z" } } }; // Making the HTTP POST request request.post({ headers: headerdata, url: externalUrl, body: JSON.stringify(payload) }, function(error, response, body){ console.log("Out body"); console.log(body); console.log("Out res"); console.log(response); sendResponse = JSON.stringify(body); console.log(sendResponse); }); //end call mulesoft // Send a success response //res.status(200).send('Received inArguments successfully.'); console.log("Out sendResponse"); console.log(sendResponse); const responseObject = { statusSend: sendResponse , statusSendID: "OK" }; //console.log('Response Object', JSON.stringify(responseObject)); return res.status(200).send(responseObject); } else { // If inArguments are missing or not an array res.status(400).send('Invalid inArguments format.'); } }) app.post('/save', (req, res) => { console.log(" test "); res.status(200).send('Success 1'); }) app.post('/validate', (req, res) => { console.log(" test "); res.status(200).send('Success 1'); }) app.post('/stop', (req, res) => { console.log(" test "); res.status(200).send('Success 1'); }) app.post('/publish', (req, res) => { console.log(" test "); res.status(200).send('Success 1'); }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })
Created from: https://expressjs.com/en/starter/hello-world.html
Loading…

no comments

    sign in to comment