2

As part of our blog subscription process, we send out an automated email, confirming someone's subscription. The email includes an image that is stored in our Marketing Cloud platform, although the email itself is sent on different a system, not from Marketing Cloud.

We now need to change the image, but we don't know its name or location, only the URL.

Is it possible to Query the name/ID of an image based on the URL? Or is the ID embedded somewhere in the URL of the image?

3

By far, the easiest method to determine the name from the image URL is to enable Predictive File URLs. If your solution needs to account for images uploaded before the enablement of that feature, or you don't want to enable it, then you can retrieve this information via the Content Builder REST API.

To note, I've tested this solution and have found the only simpleOperator that will reliably return the result you are looking for is mustcontain. Both like and contains operators return the entire catalog from Content Builder but, though the desired image should be the first item in the result set, I haven't tested this enough to say that it's reliable.

POST /asset/v1/content/assets/query HTTP/1.1
Host: YOURBASEENDPOINT.rest.marketingcloudapis.com
Authorization: Bearer YOURTOKEN
Content-Type: application/json

{
   "query":{
      "property":"fileProperties.publishedURL",
      "simpleOperator":"mustcontain",
      "value":"YOUR IMAGE URL"
   }
}
2
  • 1
    This is a great way as well! Never tried it with mustcontain operator before. – Gortonington Apr 30 at 17:00
  • Yeah, it took me a bit to stumble upon this one. It's somewhat baffling that the equals operator returns an empty result set, but at least there are workarounds. – Jason Hanshaw Apr 30 at 17:17
3

I have found the most success to be using the REST API simple query with the like operator. The caveat being instead of using the whole URL, you use just the image name at the end. E.g. myimage.png which is the last part of the URL. If you use the whole URL or any other parts of it, it will return a bunch of unrelated images and assets.

So basically something like:

GET /asset/v1/content/assets?$filter=fileProperties.publishedURL%20like%20myimage.png 
Host: {{subDomain}}.rest.marketingcloudapis.com
Content-Type: application/json
Authorization: Bearer {{authToken}}

Should return only that item to you. Now if you have multiple images with that exact file name, it will take some exploring to really break it down - but at that point you will get a return JSON that has the publishedURL of each, you can then create a for loop or similar function to find the one that exactly fits the full URL and get the info that way.

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.