SOLVED

Re: Flowboost Community Edition and Marketo APIs

Go to solution
Chris_Francis
Level 4

Flowboost Community Edition and Marketo APIs

According to the Flowboost websites, the communitity edition can connect to Marketo REST APIs.  I get the following response when attempting to do so:

{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"RangeError: You may only access Marketo-hosted assets with FlowBoost Community Edition.","trace":["Runtime.UnhandledPromiseRejection: RangeError: You may only access Marketo-hosted assets with FlowBoost Community Edition."," at process.on (/var/runtime/index.js:37:15)"," at process.emit (events.js:198:13)"," at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)"," at process._tickCallback (internal/process/next_tick.js:69:34)"]}

 Here is the code I am passing in and I have ran this in on a node.js app and it works fine there.  Any help would be appreciated.

const apiData = {
    clientId: "#######################",
    clientSecret: "#######################"
};

const evtData = JSON.parse({{lead.generic2}});

const request = {
    "input": [{
        "activityDate": (new Date().toISOString()),
        "activityTypeId": 100045,
        "attributes": [{
            "name": "Event Date",
            "value": evtData.date
        }, {
            "name": "Mobile Phone",
            "value": {{lead.Mobile Phone}}
        }, {
            "name": "Send Live Notifications",
            "value": {{lead.generic1:false}}
        }, {
            "name": "Send Recording Notifications",
            "value": true
        }],
        "leadId": {{Lead.Id}},
        "primaryAttributeValue": evtData.title
    }]
};

function getAccessToken(cb) {
    var url = `https://###-###-###.mktorest.com/identity/oauth/token?client_id=${apiData.clientId}&client_secret=${apiData.clientSecret}&grant_type=client_credentials`;
    FBHttp.fetch(url)
        .then(r => r.json())
        .then(json => { if (typeof cb === "function") cb(json.access_token) });
}

function addCustomActivity(accessToken) {
    var url = `https://###-###-###.mktorest.com/rest/v1/activities/external.json`;
    FBHttp.fetch(url, {
            "method": "POST",
            "headers": {
                "Authorization": `Bearer ${accessToken}`,
                "Content-Type": "application/json",
                "Accept": "application/json"
            },
            "body": JSON.stringify(request)
        })
        .then(r => r.json())
        .then(json => response = JSON.stringify(json, null, 5));
}

var response = null;
getAccessToken(addCustomActivity);
2 ACCEPTED SOLUTIONS

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Community Edition and Marketo APIs


According to the Flowboost websites, the communitity edition can connect to Marketo REST APIs. 

Yep, it certainly can. I'm working on such a project w/a Community key as we speak.

 

FlowBoost determines whether you're connecting to Marketo instance by seeing if the domain exists and either is a CNAME for a Marketo property or ends with .mktorest.com. So the outcome depends on the part of your code that's obfuscated, the

###-###-###.mktorest.com

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Community Edition and Marketo APIs

Are you using v20+, preferably the latest v21?

 

https://api.teknkl.com/flowboost/v21/run?authoringEnv=pro

 

Older versions restricted Marketo REST connections to Standard keys only. I think we changed that in v20 so Community keys work, too.

View solution in original post

12 REPLIES 12
Chris_Francis
Level 4

Re: Flowboost Community Edition and Marketo APIs

@SanfordWhiteman Tagging you since you are the expert in this field 🙂

SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Community Edition and Marketo APIs


According to the Flowboost websites, the communitity edition can connect to Marketo REST APIs. 

Yep, it certainly can. I'm working on such a project w/a Community key as we speak.

 

FlowBoost determines whether you're connecting to Marketo instance by seeing if the domain exists and either is a CNAME for a Marketo property or ends with .mktorest.com. So the outcome depends on the part of your code that's obfuscated, the

###-###-###.mktorest.com
Chris_Francis
Level 4

Re: Flowboost Community Edition and Marketo APIs

well the entire url https://975-FPO-828.mktorest.com which is our marketo instance and should meet all of the criteria listed and yet I still get the error posted

SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Community Edition and Marketo APIs

Are you using v20+, preferably the latest v21?

 

https://api.teknkl.com/flowboost/v21/run?authoringEnv=pro

 

Older versions restricted Marketo REST connections to Standard keys only. I think we changed that in v20 so Community keys work, too.

Chris_Francis
Level 4

Re: Flowboost Community Edition and Marketo APIs

Thanks @SanfordWhiteman That was it.  Had just cloned an old webhook and was running v19.

Chris_Francis
Level 4

Re: Flowboost Community Edition and Marketo APIs

Also after I was finally able to get the calls to work, I realized how terriblly inefficient my orignal code was.  Looked at @SanfordWhiteman article https://blog.teknkl.com/and-yes-flowboost-can-be-that-webhook-aggregator/ and refactored to be more Promise oriented.  Here is the final result:

const apiData = {
	clientId: "..........................."
	, clientSecret: "..........................."
}; 

const evtData = {"title":"An Event Tomorrow","date":"2022-06-26T03:27:00.000Z"}; 
const request = {
	"input": [{
		"activityDate": (new Date().toISOString())
		, "activityTypeId": 100045
		, "attributes": [{ 
			"name": "Event Date"
			, "value": evtData.date 
		}
		, { 
			"name": "Event Epoch Time"
			, "value": (new Date(evtData.date).valueOf() / 1000)
		}
		, { 
			"name": "Mobile Phone"
			, "value": "{{lead.Mobile Phone Number}}"
		}
		, { 
			"name": "Send Live Notifications"
			, "value": {{lead.generic1}}
		}
		, { 
			"name": "Send Recording Notifications"
			, "value": true 
		}]
		, "leadId": {{Lead.Id}}
		, "primaryAttributeValue": evtData.title 
	}] 
}; 

var result = null;

let p1 = new Promise((resolve, reject) => {
    var env = FBHttp;
	var url = 'https://###-###-###.mktorest.com/identity/oauth/token?client_id=' + apiData.clientId + '&client_secret=' + apiData.clientSecret + '&grant_type=client_credentials'; 
	env.fetch(url) 
	.then(r => r.json()) 
	.then(json => { 
		var url = "https://###-###-###.mktorest.com/rest/v1/activities/external.json";
        return env.fetch(url, { 
			"method": "POST"
			, "headers": { 
				"Authorization": 'Bearer ' + json.access_token
				, "Content-Type": "application/json"
				, "Accept": "application/json" 
			}
			, "body": JSON.stringify(request) 
		});
	})
    .then(r => r.json()) 
	.then(json => resolve(json))
	.catch(error => reject(error));
});

Promise.all([p1]).then(values => {
    if(typeof values === "object" && values.length) result = values[0];
    else result = null;
});

This worked much better.  Oddly FBHttp was undefined in the within the Promise when I tried to call it the second time.  When I pointed it to a local variable within the promise I was able to access it in the "then" but not before.

 

Thanks again Sanford for "Flowboost", your blog and literally all you do for the Marketo Community.

SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Community Edition and Marketo APIs


Thanks again Sanford for "Flowboost", your blog and literally all you do for the Marketo Community.

'welcome!

SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Community Edition and Marketo APIs

I'm not able to repro what you're saying about FBHttp being unavailable, btw. But the code would be more compact like this:

const apiData = {
    munchkinId: "...",
    clientId: "...",
    clientSecret: "..."
};

const evtData = {
    "title": "An Event Tomorrow", 
    "date": "2022-06-26T03:27:00.000Z" 
};

const eventRequest = {
    "input": [{
        "activityDate": (new Date().toISOString()),
        "activityTypeId": 100045,
        "attributes": [
            {
                "name": "Event Date", "value": evtData.date
            },
            {
                "name": "Event Epoch Time", "value": (new Date(evtData.date).valueOf() / 1000)
            },
            {
                "name": "Mobile Phone", "value": {{lead.Mobile Phone Number}}
            },
            {
                "name": "Send Live Notifications", "value": {{lead.generic1}}
            },
            {
                "name": "Send Recording Notifications", "value": true
            }
        ],
        "leadId": "90909",
        "primaryAttributeValue": evtData.title
    }]
};

var url = `https://${apiData.munchkinId}.mktorest.com/identity/oauth/token?client_id=${encodeURIComponent(apiData.clientId)}&client_secret=${encodeURIComponent(apiData.clientSecret)}&grant_type=client_credentials`;

FBHttp.fetch(url)
.then(identityRespJ => identityRespJ.json())
.then(identityResp => {
    var url = `https://${apiData.munchkinId}.mktorest.com/rest/v1/activities/external.json`;
    FBHttp.fetch(url, {
        "method": "POST",
        "headers": {
            "Authorization": `Bearer ${identityResp.access_token}`,
            "Content-Type": "application/json",
            "Accept": "application/json"
        },
        "body": JSON.stringify(eventRequest)
    })
    .then(activityRespJ => activityRespJ.json())
    .then(success)
})
.catch(failure);
Worcesterharry
Level 2

Re: Flowboost Community Edition and Marketo APIs

Hi there,

 

For what it's worth I get the same "ReferenceError: FBHttp is not defined" message in my unhandled promise rejection message, so does seem to be a small issue in the community edition.