google-slides-apigoogle-slides

Create A Color Filled Shape in the Create Request


How do I create an Red Rectangle with the Google Slides API? The following code is not working:

  var requests = [{
    createShape: {
      objectId: elementId,
      shapeType: 'RECTANGLE',
      shapeProperties: {
        shapeBackgroundFill: {
          solidFill: {
            color: {
              "themeColor": "Red"
            }
          }
        }
      },
      elementProperties: {
        pageObjectId: 'gc448bf14e8_0_0',
        size: {
          height: pt150,
          width: pt150
        },
        transform: {
          scaleX: 1,
          scaleY: 1,
          translateX: 150,
          translateY: 100,
          unit: 'PT'
        }
      }
    }
  },

GoogleJsonResponseException: API call to slides.presentations.batchUpdate failed with error: Invalid JSON payload received. Unknown name "shapeProperties" at 'requests[0].create_shape': Cannot find field.

This resource wants to Change the shape, I want to put it into original request object. Change background of google slides shape to red

Looking at this Google Resource: https://developers.google.com/slides/reference/rest/v1/presentations.pages/shapes


Solution

  • Currently the API for createshaperequest does not have shapeProperties. Only updateShapeProperties has it.

    I made two requests,

    var requests2 = [{
      updateShapeProperties: {
        objectId: elementId,
        fields: "shapeBackgroundFill.solidFill.color",
        shapeProperties: {
          shapeBackgroundFill: {
            solidFill: {
              color: {
                rgbColor: 
                {
                   red: 0.6,
                   green: 0.0,
                   blue: 0.0
                }
              }
            }
          }
        }
       }
     }];
    

    https://developers.google.com/slides/reference/rest/v1/presentations/request#createshaperequest

    https://developers.google.com/slides/reference/rest/v1/presentations/request#UpdateShapePropertiesRequest