1

We are trying to find a way to upload an image with AMPScript into Portfolio of the Email Studio (Classic Content) in the Salesforce Marketing Cloud.

I know this is possible with SOAP or REST APIs, but we need it to be done with AMPScript. SOAP API AMPscript Functions can be used though, and this is the only way as far as I understand. But when this code is executed, we get an error:

SET @portfolio = CreateObject('Portfolio')
SetObjectProperty(@portfolio, "DisplayName", "API Uploaded2")
SetObjectProperty(@portfolio, "CustomerKey", "css-grid-vs-flexbox")
SetObjectProperty(@portfolio, "FileName", "css-grid-vs-flexbox.png")

SET @resourceSpecification = CreateObject('ResourceSpecification')

SetObjectProperty(@resourceSpecification, "URN", "http://cdn.tutorialzine.com/wp-content/uploads/2017/03/css-grid-vs-flexbox.png")
SetObjectProperty(@portfolio, "Source", @resourceSpecification)

/* Add data */
SET @deStatusCode = InvokeCreate(@portfolio, @deStatusMsg, @deErrorCode)

IF @deStatusCode != "OK" THEN
    RaiseError(@deStatusMsg, 0, @deStatusCode, @deErrorCode)
ENDIF

Error Details are below:

ErrorCode=2

StatusCode=Error

Message=Exception occurred during [CreateMedia] ErrorID: 1308368347

Unfortunately, Salesforce support does not provide any support on this, and they do not have any example code in AMPScript.

I found related questions here, but none got an answer, only references to https://developer.salesforce.com which is not helpful in this case:

4
  • Have you previously had a file with same name? Even if it was deleted? If that is the case, you cannot 'create' it via the API, you will need to set the 'SaveOptions' to 'UpdateAdd'. If this doesnt work, I would remove the display name property as I believe that is automatically created by SFMC. – Gortonington May 3 '17 at 13:04
  • Thanks. No there has not been a file with the same name in Portfolio. So it should be able to 'create' an image via API. Moreover, if it was the case, I would get the 69005 Portfolio Error (developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/…), wouldn't I? I removed the display name property from the code and it didn't help. – Eduard May 3 '17 at 13:54
  • I am still getting error code 2. From the Error Codes reference (developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/…) this error code implies authentication problems, which is not obvious where the issue is. Do I need to provide Client ID and Secret (or Username and Password) somewhere in the AMPScript code? But I am really not sure about it as I thought that all AMPScript instructions were already authenticated. – Eduard May 3 '17 at 14:04
  • You are correct AMPscript API is already authenticated, do not need to add in your credentials. – Gortonington May 3 '17 at 14:16
2

The only problem with your code is that the ClientID field is missing, it will be the MID of the business unit where you need to upload your image to portfolio. I have updated this code and tested it worked fine for me.

Updated code:

    %%[

SET @portfolio = CreateObject("Portfolio")
SetObjectProperty(@portfolio, "DisplayName", "API Uploaded2")
SetObjectProperty(@portfolio, "CustomerKey", "css-grid-vs-flexbox")
SetObjectProperty(@portfolio, "FileName", "css-grid-vs-flexbox.png")

SET @ClientID = CreateObject("ClientID")
SetObjectProperty(@ClientID, "ID", "MID goes here")
SetObjectProperty(@portfolio, "Client", @ClientID )

SET @resourceSpecification = CreateObject("ResourceSpecification")

SetObjectProperty(@resourceSpecification, "URN", "http://cdn.tutorialzine.com/wp-content/uploads/2017/03/css-grid-vs-flexbox.png")
SetObjectProperty(@portfolio, "Source", @resourceSpecification)

/* Add data */
SET @deStatusCode = InvokeCreate(@portfolio, @deStatusMsg, @deErrorCode)

IF @deStatusCode != "OK" THEN
    RaiseError(@deStatusMsg, 0, @deStatusCode, @deErrorCode)
ENDIF
]%%
5
  • Indeed, it was the ClientID field. I also managed to upload a photo into Portfolio. Thank you. – Eduard May 4 '17 at 6:35
  • where do you execute this ampscript? I read that it failed via an html form in your other post, so where do you run this? – Kenneth Wagner May 9 '17 at 8:39
  • On the server side, I use a Smart Capture form with AMPScript. – Eduard Jul 28 '17 at 7:12
  • If you are interested in how to upload a file via an html form read [this post] (salesforce.stackexchange.com/questions/172897/…) as well. This task is better accomplished with Rest API. – Eduard Jul 28 '17 at 7:16
  • Will Portfolio Classic support end soon? I am doing a POC based on this code and I wonder if it is worth using this or move on to Content Builder via Rest API? Thanks – user5105 Dec 31 '18 at 18:36

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.