SOLVED

How to set scriptingObjects when script block token created through api

Go to solution
Sham_Chikkegowd
Level 1

How to set scriptingObjects when script block token created through api

Creating the script token using the end point /rest/asset/v1/folder/{id}/tokens.json?folderType=Program as attached. Token created fine. When try to use that in email template throwing the error "No usable value for scriptingObjects Expected object but got JString()". If i create the same token manually email delivers fine. The difference between API & Manual Creation is below

API Response

{"name":"test","type":"script block","value":"{\"codeBlock\":\"#set($ed1 = \\\"ok\\\")\",\"scriptingObjects\":\"\"}"}

Manual One

{"name":"test","type":"script block","value":"{\"codeBlock\":\"#set($ed1 = \\\"ok\\\")\",\"scriptingObjects\":{}}"}

So how to set scriptingObjects through api call ?

API.png

Thanks for your time.

cc:Sanford Whiteman

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How to set scriptingObjects when script block token created through api

Thanks for revealing more of the problematic environment.

The "good" news is I can reproduce the same problem now that you mention it only occurs with triggered campaigns.

The bad news is I can't find a workaround for the instances in which it doesn't work. This is probably linked to the fact that the VTL token type isn't officially supported for updates via the Asset API. The undocumented "script block" type is functional (I've used it a ton at a couple of clients) but it seems that it hasn't been put through its paces for trigger campaigns. (The clients in question only send batches, AFAIK, though I'll also check in their instances to see if it actually works for triggers there, as it does in your Sandbox.)

I'll open a case about this to see if we can get more traction. Nice job figuring it out.

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: How to set scriptingObjects when script block token created through api

Can't repro this. scriptingOptions isn't part of the API contract and isn't required to send an email that includes the VTL {{my.token}}.

I note that your token doesn't output anything. Is there another, later token drawing on this one for output? Is the token truly in the template? Where is it placed exactly?

Sham_Chikkegowd
Level 1

Re: How to set scriptingObjects when script block token created through api

Thanks Sanford Whiteman​ for faster quickly. We went with solution & validate in Sandbox & QA Environment where it worked fine. But in production it is not working. The error message matches with difference we are seeing in scriptingOption. Also scriptingOption missing in other environment also but still works.

You are right Currently token just sets the event description. This is first token added in template. Later we have business logic drawing on that variable to render different variation. Just for debug in production template just added {{my.test:default=}} It throws "No usable value for scriptingObjects Expected object but got JString()".

Some additional info we gathered during debug & might give some hints

Please note in problematic environment

  1. If i use schedule campaign the same template works when token is created through API.
  2. We are using is triggered campaign ( lead is pushed from api) & throwing the error .
  3. If i create the token manually rather than setting through api the same template works for triggered campaign

Any clue you can provide is highly appreciated ? Also engaged official support just tagging without much progress.

Thanks in advance.

SanfordWhiteman
Level 10 - Community Moderator

Re: How to set scriptingObjects when script block token created through api

Thanks for revealing more of the problematic environment.

The "good" news is I can reproduce the same problem now that you mention it only occurs with triggered campaigns.

The bad news is I can't find a workaround for the instances in which it doesn't work. This is probably linked to the fact that the VTL token type isn't officially supported for updates via the Asset API. The undocumented "script block" type is functional (I've used it a ton at a couple of clients) but it seems that it hasn't been put through its paces for trigger campaigns. (The clients in question only send batches, AFAIK, though I'll also check in their instances to see if it actually works for triggers there, as it does in your Sandbox.)

I'll open a case about this to see if we can get more traction. Nice job figuring it out.

Sham_Chikkegowd
Level 1

Re: How to set scriptingObjects when script block token created through api

Appreciate spending time on this issue to help us out.

SanfordWhiteman
Level 10 - Community Moderator

Re: How to set scriptingObjects when script block token created through api

OK, I just found the workaround, which is... a strange one, even for me.

If you follow me, we can set up time to chat about it. Prefer to not get into it publicly yet.

Adam
Level 2

Re: How to set scriptingObjects when script block token created through api

How did you solve this? I am having the same issue with Triggers and my script blocks. I have also found that as of the end of Feb 2020 I am no longer able to do get the script block to push into Marketo. Do you have a workaround (We use scriptblock as your HashMap for data)