wmclaxton
wmclaxton

Reputation: 35

social media link inside a SendGrid dynamic template

I am trying to add a social media link inside a SendGrid dynamic template, specifically it's a link to share something via LinkedIn. The social media link invokes a RESTful API and so has a number of parameters to be provided, much like a form. The problem is that, unless these parameters are 'percent-encoded', SendGrid's editor will generate an error.

Here is a URL which is intended to enable the email recipient to add a certificate of achievement to their LinkedIn profile. It was created following these instructions.

https://www.linkedin.com/profile/add?startTask=FS_Cert&name=Certificate%20Of%20Achievement&organizationId=26650704&issueYear=2021&issueMonth=6&certId=20210622-001&certUrl=https://certificates.nextid.com/certificate?id%3D291b71fb-79cb-4db4-bfa6-108d0c9eb2d6

This URL almost works, but - because it contains a nested URL as the last parameter - I need to change the final '=' to '%3D'. With this minor modification, I can open an email client like Thunderbird and paste it in as HTML (ie- as the target of a link) and the certificate can be added to the recipient's LinkedIn profile. I can also add an image to make it a clickable button.

But, if I take this URL and paste it into a dynamic template in SendGrid, the ampersands '&' cause the editor to object with the error: 'named entity expected, got none'. I change those to %26 and end up with this modified URL, which does not cause any error in the SendGrid editor.

https://www.linkedin.com/profile/add?startTask=FS_Cert%26name=Certificate%20Of%20Achievement%26organizationId=26650704%26issueYear=2021%26issueMonth=6%26certId=20210622-001%26certUrl=https://certificates.nextid.com/certificate?id%3D291b71fb-79cb-4db4-bfa6-108d0c9eb2d6

Unfortunately, this URL no longer works when you paste it into the browser and the link that is created in the SendGrid email does not resolve properly. The RESTful API call is executed, but the parameters are not passed through.

Does anyone have a suggestion on how to insert the RESTful API URL into the SendGrid email without causing the editor to reject it. Some Javascript perhaps?

Upvotes: 0

Views: 1873

Answers (1)

wmclaxton
wmclaxton

Reputation: 35

This issue was resolved with the correct URL escape characters and turning off SendGrid link tracking.

  1. Because we're delimiting arguments in HTML (the SendGrid Editor uses HTML), the correct escape character for '&' is '&' and not '%26'. It only becomes a URL in the email that's sent. We still need to use percent substitution to change '=' to %3D in the last parameter, because that equals sign is embedded inside a URL in the certUrl parameter. We also need to convert spaces to '%20'. So the final modified link should be:
https://www.linkedin.com/profile/add?startTask=FS_Cert&name=Certificate%20Of%20Achievement&organizationId=26650704&issueYear=2021&issueMonth=6&certId=20210622-001&certUrl=https://certificates.nextid.com/certificate?id%3D291b71fb-79cb-4db4-bfa6-108d0c9eb2d6
  1. However this is getting munged (messed up) because the SendMail link tracking feature modifies the URL. The URL parameters were always being truncated and not passed through to the LinkedIn Profile form, apparently due to rewriting of the SendGrid tracking URL in the browser. So I added the parameter "clicktracking=off" to the link tag and now it is working (and is easier to debug). Here is the final version:
<a clicktracking=off
href="https://www.linkedin.com/profile/add?startTask=FS_Cert&amp;name=Certificate%20Of%20Achievement&amp;organizationId=26650704&amp;issueYear=2021&amp;issueMonth=6&amp;certId=20210622-001&amp;certUrl=https://certificates.nextid.com/certificate?id%3D291b71fb-79cb-4db4-bfa6-108d0c9eb2d6">

Upvotes: 1

Related Questions