Update dynamic image content by API

filip_rachunek
Level 2

Update dynamic image content by API

Hi, I have a few questions regarding modification dynamic image content in emails by Rest API. Generally I need update alternative text, but to update just this property, it is neccessary provide request with all content arguments (image url, alt text, with, style...). See issues bellow.

 

1. Sometimes it is not possible to update image due to Invalid URL error. See for example image content bellow (dynamic image content):
GET /rest/asset/v1/email/1717/dynamicContent/RVMtc2luZ2xl.json
Response:
[
      {
        "createdAt": "2022-04-06T14:47:45Z+0000",
        "updatedAt": "2022-04-06T14:47:45Z+0000",
        "id": 1717,
        "segmentation": 1011,
        "content": [
          {
            "id": "MTMzMg**",
            "segmentId": 1041,
            "segmentName": "Default",
            "content": "https://via.placeholder.com/1200x400",
            "type": "Image",
            "width": "600",
            "altText": "MULTIPLE.PNG",
            "linkUrl": "https://via.placeholder.com/1200x400",
            "style": "-ms-interpolation-mode: bicubic; outline: none; border-right-width: 0; border-bottom-width: 0; border-left-width: 0; text-decoration: none; border-top-width: 0; display: block; max-width: 100%; line-height: 100%; height: auto; width: 600px"
          },
          ...
        ]
      }
    ]
 
And if I try to update segment by API with the same url that was configured in UI, it fails. This happens only for some URLs. See request and response bellow.
POST /rest/asset/v1/email/1717/dynamicContent/RVMtc2luZ2xl.json
Body: segment=Default&type=Image&externalUrl=https://via.placeholder.com/1200x400&altText=updated-alt-text
Response:
{
      "success": false,
      "errors": [
        {
          "message": "Invalid URL",
          "code": "701"
        }
      ],
      "requestId": "11ea3#18008f813ba",
      "warnings": []
    }
 
Are there any restrictions in url validation? Why modification in UI works but it fails for API call?

 

 

2. Is it possible somehow update segmented image content of File type (image uploaded from my computer)?
See dynamic image content bellow:
GET /rest/asset/v1/email/1717/dynamicContent/RVMtYXJ0aWNsZTQ=.json

[
      {
        "createdAt": "2022-04-08T11:53:10Z+0000",
        "updatedAt": "2022-04-08T11:53:10Z+0000",
        "id": 1717,
        "segmentation": 1011,
        "content": [
          {
            "id": "MTM0NQ**",
            "segmentId": 1041,
            "segmentName": "Default",
            "content": "5396",
            "type": "File",
            "contentUrl": "http://063-RVK-838.mktoweb.com/rs/063-RVK-838/images/marketo-image-from-computer.png",
            "height": "auto",
            "width": "270",
            "altText": "marketo-image-from-computer.png",
            "style": ""
          }
        ]
      }
    ]
I tried the following API request, but it fails with `Invalid data for Type.` message.
POST /rest/asset/v1/email/1717/dynamicContent/RVMtc2luZ2xl.json
Body: segment=Default&type=File&contentUrl=http://063-RVK-838.mktoweb.com/rs/063-RVK-838/images/marketo-image-from-computer.png&altText=updated-alt-text
Response:
{
      "success": false,
      "errors": [
        {
          "message": "Invalid data for Type.",
          "code": "701"
        }
      ],
      "requestId": "4724#1800912a367",
      "warnings": []
}

 

 

3. Is it possible detect by API call that segmented image has locked size? The issue is that I want to change dynamic image content but I don't know whether image size is locked or not, so if size is locked and image width is provided in update request it fails with `Error processing Image: Image size is locked in email template. Cannot edit image size`. This error occurs even if file size is not changed.
GET /rest/asset/v1/email/1717/dynamicContent/RVMtc2luZ2xl.json
Response:
[
      {
        "createdAt": "2022-04-06T14:47:45Z+0000",
        "updatedAt": "2022-04-06T14:47:45Z+0000",
        "id": 1717,
        "segmentation": 1011,
        "content": [
          {
            "id": "MTMzMg**",
            "segmentId": 1041,
            "segmentName": "Default",
            "content": "https://via.placeholder.com/1200x400",
            "type": "Image",
            "width": "600",
            "altText": "MULTIPLE.PNG",
            "linkUrl": "https://via.placeholder.com/1200x400",
            "style": "-ms-interpolation-mode: bicubic; outline: none; border-right-width: 0; border-bottom-width: 0; border-left-width: 0; text-decoration: none; border-top-width: 0; display: block; max-width: 100%; line-height: 100%; height: auto; width: 600px"
          },
          ...
        ]
      }
    ]
And modification request:
POST /rest/asset/v1/email/1717/dynamicContent/RVMtc2luZ2xl.json
Body: segment=Default&type=Image&externalUrl=https://placekitten.com/200/300&a&altText=updated-alt-text&width=600
Response:
    {
      "requestId": "4a3e#18009178a1c",
      "success": false,
      "warnings": [],
      "errors": [
        {
          "code": "611",
          "message": "Error processing Image: Image size is locked in email template. Cannot edit image size"
        }
      ]
    }
 
 
Thanks a lot
Tags (2)
8 REPLIES 8
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Update dynamic image content by API

1. This is a known issue, and probably the difference b/w the images that load and doesn't load is the presence of CORS header in the once that do load - there's an old thread linked here FYR.

2. Can you try hitting the endpoint with the type = Image and value = <image asset-Id-in-DS> parameters along with the segment  parameter? Guess this should do the trick!

3. The getcontent endpoint does return the isLocked Boolean attribute, but I'm not 100% sure if isLocked attribute's value for the image modules do mean the image dimensions are adjustable and un-locked at the template level.

filip_rachunek
Level 2

Re: Update dynamic image content by API

Thank you for response.

 

2. I tried your solution and it did the trick. Thank you

3. I checked  isLocked attribute in getcontent endpoint and the value seems to be independent of lock image size value. So there is probably no way how to get lock image size attribute value, except reading plain email template and parse the value from html.

 

Actually in our scenario we just need update altText of Image, but to modify it, it's necessary provide all other attributes in update request (POST /rest/asset/v1/email/{emailId}/dynamicContent/{dynamicContentId}.json). It is strange that it is not possible to use same values that were returned by read endpoint  (GET /rest/asset/v1/email/{emailId}/dynamicContent/{dynamicContentId}.json). This makes all quite challenging. Do you think there is a chance this could be addressed sometimes in the future?

 

Thanks

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Update dynamic image content by API


 

3. I checked  isLocked attribute in getcontent endpoint and the value seems to be independent of lock image size value. So there is probably no way how to get lock image size attribute value, except reading plain email template and parse the value from html.

 


That's what I inferred from my testing, 👍 I tried looking up in the documentation but couldn't find much!

 

Well, segment, type, and value are the mandatory attributes for the POST request - you can store these values locally and use it in-case if you just want to update the alt-text, I think that shouldn't cause any issues.

filip_rachunek
Level 2

Re: Update dynamic image content by API


Well, segment, type, and value are the mandatory attributes for the POST request - you can store these values locally and use it in-case if you just want to update the alt-text, I think that shouldn't cause any issues.


Yes, I tried it and that's possible. But there is a problem that if e.g. style parameter is not in the request, the value in the email is not preserved. That's not a problem when the value is the same as in the email template, but if there are some changes, the value is overwritten by value from the template. Same also applies for other parameters: widthheight ...

 

Thanks

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Update dynamic image content by API

Yeah - w/o the optional params the default values (in this case the template styles) would be applied on a POST call. TBH, it could be just me, but smh I feel that this EP is not that widely used.

adanand
Level 2

Re: Update dynamic image content by API

Hi,

I am also trying to update the email image alt text using Dynamic Content API of Marketo, however, ran into an issue of the email image alt text updation breaking the email image itself. Sharing the steps I followed below. Any related experience sharing is much appreciated. Thanks!


I am trying to run an API call to retrieve and update the Dynamic content of the Email Image alt text.

I am running 2 API calls

(1) GET : GET /rest/asset/v1/email/{id}/dynamicContent/{contentId}.json to get the content id and the type of the email module (https://developers.marketo.com/rest-api/endpoint-reference/asset-endpoint-reference/#!/Emails/getEma...). I am using the dynamic content GET call to extract: segmentation name, segmentation ID, content ID, content type, emailID, dynamic content type, dynamic content ID.

(2) POST : I am using the Dynamic Content POST to update the Dynamic email image alt text Dynamic Content after retrieving the emailID, Dynamic Content, Dynamic Content ID, segment name, segment ID.
However, when I try to update the image URL alt text using this POST API call, after adding the specific altText parameter under "$Params" for this specific dynamic section upload type, it updates the image URL alt text but it breaks the Marketo email image itself. Can you please advise a way that it should not break the email image module?

Any guidance you can provide is much appreciated.

 

Thanks

SanfordWhiteman
Level 10 - Community Moderator

Re: Update dynamic image content by API

Please open a new thread for this, thanks. You can refer back to this one if necessary.

 

Also, instead of merely describing your payload, include the actual payload using the Syntax Highlighter (See Jo's blog post on how to do this here). This way we know what actually went on the wire.

adanand
Level 2

Re: Update dynamic image content by API