Take the community feedback survey now.

Programmatically upload Media to Optimizely SaaS CMS

Vote:
 

I am trying to upload jpg programmatically to Optimizely SaaS CMS. I am running into issues mentioned below.  

I am trying via straight up REST API, trying it using postman. But I would be open to other options like using C# Optimizely Graph SDK (if that is an option). 

This is what I have tried so far. 

  1. I was not able to create image in one step (one POST request),  so I broke it down into two requests.
  2. The first is creating a item (an ImageMedia content type item) without the image.  Here is the POST request

          POST URL:  https://api.cms.optimizely.com/preview3/experimental/content

          Body JSON: 

          {

               "key": "40531ff4780340e0a9283ce779f2f188",
               "contentType": "ImageMedia",
               "displayName": "abc.jpg",
               "locales": {
                  "": {
                         "displayName": "abc.jpg",
                          "status": "published"
                      }
               },
               "container": "179dea020f154673844f76de7fd1b630"
        }
 
        It creates the item in the correct path. but without the actual media file  (since I have not specified the media file)
        

3.  The next request is a Patch request,  I update the same item id with the actual file,  abc.jpg

       PATCH Request URL:  https://api.cms.optimizely.com/preview3/experimental/content/40531ff4780340e0a9283ce779f2f188  

       I attach abc.jpg to the file parameter, and set Content-Type to multipart/form-data

       Here it the curl request

       curl --location --request PATCH 'https://api.cms.optimizely.com/preview3/experimental/content/40531ff4780340e0a9283ce779f2f188' \
              --header 'Content-Type: multipart/form-data' \
              --header 'Authorization: Bearer <my-bearer-token>
              --form 'file=@"/C:/temp/abc.jpg"' \
               --form 'Content-Type="multipart/form-data"'

       

This request fails with a 415 Unsupported media type error. 

 

#340586
Oct 03, 2025 20:01
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.