0

Is there a way to get a content block with AMPScript using API? I want to run an AMPScript using marketing cloud API. The only option I can think of is to create a content block with the AMPScript and retrieve that content block with the Marketing cloud API. but I can't find a method that does that. What is the best practices to do that?

Update: I want to use ClaimRow with the API to get a unique coupon code.

2
  • This sounds like a very high frequency and volume API solution - which is not very sustainable for SFMC as the platform is not intended for usage in this way. I think this would be better handled via a SQL query inside SFMC and then using the API to retrieve the associated coupon code or to handle this claiming outside of SFMC and just store that data inside a DE. – Gortonington Feb 1 at 14:45
  • @Gortonington - I agree with your points, however if the logic is to use same DE for claiming rows within emails and occasionally request one via "API", I would say this is still feasible. Otherwise, if the goal is to claim thousands of rows daily, not so much. – Lukas Lunow Feb 1 at 18:42
0

This sound more like a use case for CloudPages Code Resource. Retrieving a content block using API will not result in executing the AMPscript within, as this only happens during Preview, Send or VAWP contexts.

You can use JSON code resource to execute the Ampscript, and print the output e.g. in this type of structure:

{
    "voucher": "XYZ123",
    "contactKey": "0031232c5e3db2",
    "claimed": "2021-03-23T18:25:43.511Z"
}

Your code should consist of two parts, one with logic claiming the voucher - receiving the contactKey, or other identificator of the person you assign the voucher to, from a request parameter.

And second part printing the output, e.g. like this:

{
    "voucher": "%%=v(@vouchercode)=%%",
    "contactKey": "%%=v(@contactkey)=%%",
    "claimed": "%%=v(@claimedtime)=%%"
}

Be mindful that these code resources reside at publicly available URLs, and are not secure. So you should take applicable precautions to prevent unauthorised execution of your Ampscript.

4
  • Hi Thank you for your response. I want to use ClaimRow with the API to get a unique coupon code. – DanielRomano Feb 1 at 12:12
  • Please update your question with this information, @DanielRomano - so we are able to provide better answers – Lukas Lunow Feb 1 at 12:13
  • Thanks, Post Edited – DanielRomano Feb 1 at 13:24
  • I have adapted my answer accordingly, @DanielRomano . There are multiple posts here, describing the logic of ClaimRow and ClaimRowValue, why I don't go into details on these topics. – Lukas Lunow Feb 1 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.