2

I'm thinking of using the HTTPGet() function in the following Ampscript of an email...

var @ItemId,
    @ItemAsset,
    @ItemAssetCall,
    @ItemAssetCallStatus

set @ItemId = '1234'
set @ItemAsset = Concat('http://www.example.com/items/item-',@ItemId,'.png')
set @ItemAssetCall = HTTPGet(v(@ItemAsset),true,1,@ItemAssetCallStatus)

if @ItemAssetCallStatus < 0 then 
  set @ItemAsset = "http://www.example.com/items/item-default.png"
endif

... to see if an image or asset exists on the server (in this case, a png). I am really relying on the CallStatus portion of the function.

I would like to know if there is any downsides to using HTTPGet this way? Is there some scenario I haven't planned for with this set up, in terms of the Ampscript having to wait on the server's response, or the email delaying because it wasn't meant to be used this way, things of that nature.

The reason I'm using this and not something like the Image() Content Ampscript function is I need a bit more control over the image tag.

3

Firstly, you don't need to print (v) a variable if you are using it inside an AMPscript block. You can change:

set @ItemAssetCall = HTTPGet(v(@ItemAsset),true,1,@ItemAssetCallStatus)

to:

set @ItemAssetCall = HTTPGet(@ItemAsset,true,1,@ItemAssetCallStatus)

To answer your question, I've tried requesting different status codes using HTTPGet to httpstat.us and it appears that 2xx and 3xx status codes all return 0 status (which is what you want), while 4xx and 5xx return -2. So, I believe should be fine to rely on the call status!

1
  • Just wanted to add to this in case anyone else was looking into this solution, that we've been using this to reference external images for a store footer content block with no issues, we send approx. 1.3 million emails a day. Thanks for the help Eliot!
    – Daniel D.
    Jan 30 '18 at 1:25

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.