Skip to content

Instantly share code, notes, and snippets.

@eduardobatistadev
Forked from leto96/SMSDynamicBitlyLink.js
Last active September 1, 2023 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardobatistadev/ced0ee33fd56592cf7c40857011e1922 to your computer and use it in GitHub Desktop.
Save eduardobatistadev/ced0ee33fd56592cf7c40857011e1922 to your computer and use it in GitHub Desktop.
Create Dynamic links using Bit.ly API in Marketing Cloud SMS Send, with AMPScript and Guide Template Language
// Ampscript - Integracao com bitly que encurta URL dinamicamente enviada por SMS.
%%[
var @cloudpage, @link, @param, @bitlyPage, @contentType, @content,
@bitlyToken, @additionalHeaderName, @additionalHeaderValue, @request, @response,
@message
set @bitlyToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' // Your bitly Token
set @bitlyPage = 'https://api-ssl.bitly.com/v4/bitlinks'
set @contentType = 'application/json'
set @additionalHeaderName = 'Authorization'
set @additionalHeaderValue = concat('Bearer ', @bitlyToken)
set @param = AttributeValue('Id'); // Or Any Attribute
set @cloudpage = 'https://yourdomain.com/something'
set @link = concat(@cloudpage, '?yourparam=', @param)
set @content = concat('{"long_url": "',@link,'"}')
set @request = HTTPPost(@bitlyPage, @contentType, @content, @response,
@additionalHeaderName, @additionalHeaderValue)
set @message = 'Hello, this is my link :'
]%%%%=v(@message)=%%{{.datasource response type=variable}}{{.data}}{ "target" : "@response" }{{/data}}{{link}}{{/datasource}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment