Marketo Token Create API call throw 709 Business Rule Violation Error

tdesai
Level 2

I am running into an issue where my API call to create token is failing. The error response is 709 (Business Rule Violation) with message saying Not a valid Script Token value.

 

I am using the following documentation for reference - https://developers.marketo.com/rest-api/endpoint-reference/asset-endpoint-reference/#!/Tokens/addTok... 

 

Token data type = script block (NOTE: I did not find official documentation of this data type https://developers.marketo.com/rest-api/assets/tokens/)

 

Please check the HTTP request & response screenshots below.

HTTP Response

marketo_token_error_response_png_2739×1499_.png

HTTP Request

marketo-token-error.png

 
15 REPLIES 15
SanfordWhiteman
Level 10 - Community Moderator

The script token type is deprecated via API; even when it works, you have to do some advanced Velocity to actually use the code.

 

The specific reason this call isn't working is because you aren't encoding the payload correctly, but I'd encourage you to avoid writing this token type via API. What is the overall logic that you're trying to implement from a business perspective?

tdesai
Level 2

I am trying to render dynamic content in the email. I am trying to do this by setting an array of json objects via the token API call  -

$defaultDocs velocity script variable eg.

 

 

#set($defaultDocs = [{id:1, url: 'test.url.com', title:'test link1'}, ...])

 

 

I have a separate token at the email program level (this one I set via MarketoUI and NOT via API call reason being this is "static" vs the above one) where-in I do a for loop over this array collection like so

 

 

 

#set($urls=[])
#foreach($doc in $defaultDocs)
$urls.add($doc.url)
#end
#foreach($doc in $defaultDocs)
#set($i = $foreach.count - 1)
<a href="https://${urls[$i]}">$doc.title</a>
#end

 

 

 

 

SanfordWhiteman
Level 10 - Community Moderator

velocity script variable eg.
#set($defaultDocs = [{id:1, url: 'test.url.com', title:'test link1'}, ...])

Hmm, that's not valid Velocity code, though. (Nor is it valid JSON, though Velocity only supports a subset of JSON.)

 

Anyway....

 

Is this used in a Trigger context, Batch, or both? (Yes, this matters.)

 

 

 

 

tdesai
Level 2

Sorry about that I shared pseudo code to share my design.

We schedule the campaign (type is batch) via api call https://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Campa...

Here's the rectified code -

 

#set($defaultDocs = [{"Id":1, "Url": "test.url.com", "Title":"test link1"}, ...])

Our workaround is to refer to the lead object.
${lead.userId}#set($defaultDocs = [{"Id":1, "Url": "test.url.com", "Title":"test link1"}, ...])

 

SanfordWhiteman
Level 10 - Community Moderator

Here's the rectified code -

#set($defaultDocs = [{"Id":1, "Url": "test.url.com", "Title":"test link1"}, ...])

OK, that'll compile at least. Note what I mean by "subset of JSON" is VTL literals don't support C-style escapes, nor the literal keyword null.

 

I don't understand what your workaround is intended to do, though.

tdesai
Level 2

In my work around I am accessing marketo object and I am thinking that is the reason it worked.

SanfordWhiteman
Level 10 - Community Moderator

 

${lead.userId}#set($defaultDocs = [{"Id":1, "Url": "test.url.com", "Title":"test link1"}, ...])

This code is just outputting a lead field directly before setting a variable.

 

tdesai
Level 2

Yes. Looks like if I access a marketo object in my script code then the API call to create the token is success and I don't get the 709 Business Violation Error. Again this is purely a workaround!

SanfordWhiteman
Level 10 - Community Moderator

Less a workaround than luck — if this works, it's because the parser that checks for valid content is broken, but there's no reason to assume it'll stay broken (esp. since the whole endpoint isn't supported).

 

I co-develop a commercial app that used to consume this endpoint, but we encountered far too many regressions over time and turned it off late last year. It's too risky to keep in production now.

tdesai
Level 2

Thank you so much for your input! This definitely raises a red flag in our current design. 

tdesai
Level 2

Hello again! Would you know if marketo supports creating/updating email script tokens via the UI?

SanfordWhiteman
Level 10 - Community Moderator

This is a quite surprising question because the way everyone creates Email Script (Velocity) tokens is via the UI, in the Program » My Tokens tab.

amasaraure
Level 1

I have been following this thread  with much interest and has the same concern. If the developer does not want  to create email scripts( velocity) directly in the UI  and would would like  to use the token api,  which datatype should they use, since script block was deprecated.

Do you see any design problems with this approach? Does Marketo in the future has plans to expose the api that allow developers to send a custom velocity script token via api to email programs residing in Marketo.

SanfordWhiteman
Level 10 - Community Moderator

Why don't you explain exactly what your business case is? That may give insight into other ways to do it.

 

Injecting VTL code via the API is far from a typical need. 

amasaraure
Level 1

Business cased removed