ShotStack with Google sheet

Hi , Im new her any help how can i apply ShotStack with Google Script . thank You !

You can use the UrlFetchApp class. This allows you to send POST requests.

The below uses the templates/render endpoint.

const url = "https://api.shotstack.io/v1/templates/render";

const payload = {
  id: "be86bfc2-a19b-4ab6-aa6c-f70242a388fc",
  merge: [
    {
      find: "name",
      replace: "Noure"
    }
  ]
};

const options = {
    "method": "post",
    "headers": {
        "Content-Type": "application/json",
        "x-api-key": "YOUR_API_KEY"
    },
    "payload": JSON.stringify(payload)
};

function render() {
  const response = UrlFetchApp.fetch(url, options);
  console.log(response.getContentText());
}
1 Like

Thank You Sir ! *
i tried the same Script But i get This Error response : I tried [Create Template method]

Exception: Request failed for https://api.shotstack.io returned code 403. Truncated server response: {“message”:“Forbidden”} (use muteHttpExceptions option to examine full response)

note *: i Change the key api and the ID but i get Error

What url are you using? Normally 403 error have to do with using the wrong url or API key.

1 Like

i used same method you Posted But i get same message Error .

this is what i Want the same Work like this Refrence :

but: [i Like to apply with Google Script ] .

Thank you very Much for Your help
[Your App must Be on the Top 1]

Could you share your code? Just make sure to obscure your API key.

1 Like

Yes !
here is My Api Key : XXXXXXXXXXXXXXXXXXXXXXXXXX

:smiling_face_with_three_hearts:

Please don’t share your API key publicly. This may lead to it being abused and you losing your credits.

Can you share the code you’re using with Google Script? I can take a look at what may be the issue. Just make sure to not include your API key.

1 Like

Fist Im trying to Update Template after updating i go to the next step and i make render to that specific template .

Summary
const link = "https://api.shotstack.io/V1/templates/36158755-b022-4f63-b438-d2a123160dae";

const updateTemp = {
    "timeline": {
        "soundtrack": {
            "src": "https://feeds.soundcloud.com/stream/1029352582-unminus-neuron-parking.mp3",
            "effect": "fadeOut"
        },
        "fonts": [
            {
                "src": "https://templates.shotstack.io/basic/asset/font/barlow-extrabold.ttf"
            },
            {
                "src": "https://templates.shotstack.io/basic/asset/font/barlow-regular.ttf"
            }
        ],
        "background": "#000000",
        "tracks": [
            {
                "clips": [
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.ap-southeast-2.amazonaws.com/logos/contemporary-color-white.png"
                        },
                        "start": 0,
                        "length": 3,
                        "fit": "none",
                        "scale": 0.8,
                        "offset": {
                            "y": 0.16
                        },
                        "transition": {
                            "in": "slideDown",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>February at The Aviary</p>",
                            "css": "p { font-family:'Barlow ExtraBold'; color: #FFFFFF; font-size: 68px; text-align: center; }",
                            "width": 800,
                            "height": 140
                        },
                        "start": 0.8,
                        "length": 2.2,
                        "offset": {
                            "y": -0.13
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "luma",
                            "src": "https://templates.shotstack.io/basic/asset/video/luma/circles/circle-expand-right.mp4"
                        },
                        "start": 3,
                        "length": 2
                    },
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://images.pexels.com/photos/326279/pexels-photo-326279.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"
                        },
                        "start": 0,
                        "length": 4,
                        "effect": "zoomIn"
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Lunch Menu</p>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #FFFFFFFF; font-size: 80px; text-align: left; }",
                            "width": 600,
                            "height": 100
                        },
                        "start": 3.4,
                        "length": 3.1,
                        "position": "topLeft",
                        "offset": {
                            "x": 0.02,
                            "y": -0.15
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>&nbsp;</p>",
                            "width": 650,
                            "height": 120,
                            "background": "#FF0000"
                        },
                        "start": 3,
                        "length": 3,
                        "position": "left",
                        "offset": {
                            "y": 0.3
                        },
                        "transition": {
                            "in": "slideLeft",
                            "out": "slideLeft"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://images.pexels.com/photos/3434523/pexels-photo-3434523.jpeg?cs=srgb&dl=pexels-mister-mister-3434523.jpg&fm=jpg",
                            "crop": {
                                "left": 0,
                                "right": 0
                            }
                        },
                        "start": 3,
                        "length": 3.5,
                        "fit": "contain",
                        "position": "left",
                        "transition": {
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Shrimp Grill</p><br><div>Grilled shrimp with teriyaki sauce</div><br><br><p>Spring Roll</p><br><div>Spring roll filled with meat and vegetables</div><br><br><p>7ami Hrissa</p><br><div>Sushi roll different flavors</div><br><br><p>Niguiri</p><br><div>Rice balls with seaweed</div>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #FF1a1a1a; font-size: 50px; text-align: left; line-height: 80%;} div { font-family: 'Barlow Regular'; color: #FF1a1a1a; font-size: 40px; text-align: left; line-height: 80%;} br { line-height: 50%}",
                            "width": 600,
                            "height": 850
                        },
                        "start": 3.5,
                        "length": 3,
                        "offset": {
                            "x": 0.1
                        },
                        "transition": {
                            "in": "slideLeft",
                            "out": "fade"
                        }
                    },
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>$20.60</p><br><br><br><br><br><br><br><br><p>$20.90</p><br><br><br><br><br><br><br><p>$12.20</p><br><br><br><br><br><br><br><p>$12.20</p><br><br>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #ff6600; font-size: 50px; text-align: left ;line-height: 80%;} br { line-height: 100%} ",
                            "width": 180,
                            "height": 850
                        },
                        "start": 3.5,
                        "length": 3,
                        "position": "right",
                        "offset": {
                            "x": -0.1
                        },
                        "transition": {
                            "in": "slideLeft",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>&nbsp;</p>",
                            "width": 900,
                            "height": 900,
                            "background": "#FFFFFF"
                        },
                        "start": 3,
                        "length": 3.5,
                        "position": "right",
                        "offset": {
                            "x": -0.1
                        },
                        "transition": {
                            "out": "slideLeft"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "luma",
                            "src": "https://templates.shotstack.io/basic/asset/video/luma/circles/circle-expand-left.mp4"
                        },
                        "start": 6,
                        "length": 2
                    },
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.ap-southeast-2.amazonaws.com/backgrounds/bg-aviary-1.jpg"
                        },
                        "start": 3,
                        "length": 4,
                        "effect": "zoomIn"
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Award Winning Chef Won Chaw</p><br><span>Specials of the month</span>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #FFFFFF; font-size: 80px; text-align: center; line-height: 80%;} span { font-family: 'Barlow Regular'; color: #FFFFFF; font-size: 60px; text-align: center; line-height: 80%;}",
                            "width": 700,
                            "height": 250
                        },
                        "start": 6.8,
                        "length": 2.2,
                        "offset": {
                            "x": 0.2,
                            "y": 0.25
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>&nbsp;</p>",
                            "width": 60,
                            "height": 300,
                            "background": "#ff6600"
                        },
                        "start": 6,
                        "length": 3,
                        "position": "left",
                        "offset": {
                            "y": 0.25
                        },
                        "transition": {
                            "in": "slideLeft",
                            "out": "slideLeft"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>&nbsp;</p>",
                            "width": 60,
                            "height": 300,
                            "background": "#ff6600"
                        },
                        "start": 6,
                        "length": 3,
                        "position": "right",
                        "offset": {
                            "y": 0.25
                        },
                        "transition": {
                            "in": "slideRight",
                            "out": "slideRight"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "luma",
                            "src": "https://templates.shotstack.io/basic/asset/video/luma/circles/circle-expand-right.mp4"
                        },
                        "start": 9,
                        "length": 2
                    },
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://images.pexels.com/photos/3873973/pexels-photo-3873973.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"
                        },
                        "start": 6,
                        "length": 4,
                        "effect": "zoomIn"
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.ap-southeast-2.amazonaws.com/images/dish3.png"
                        },
                        "start": 9,
                        "length": 3.5,
                        "fit": "contain",
                        "scale": 0.35,
                        "effect": "zoomIn",
                        "offset": {
                            "x": -0.25
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Grill</p>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #11000000; font-size: 260px; text-align: left; }",
                            "width": 500,
                            "height": 300
                        },
                        "start": 9.4,
                        "length": 3.1,
                        "position": "topLeft",
                        "offset": {
                            "x": 0.05
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Grilled Banderilles</p>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #FFff6600; font-size: 140px; text-align: left; line-height: 70%; }",
                            "width": 800,
                            "height": 280
                        },
                        "start": 9.5,
                        "length": 3,
                        "offset": {
                            "x": 0.16,
                            "y": 0.25
                        },
                        "transition": {
                            "in": "slideLeft",
                            "out": "fade"
                        }
                    },
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Sweet and sour pork with peppers, onions and pineapple bathed in barbecue sauce.</p>",
                            "css": "p { font-family: 'Barlow Regular'; color: #FF1a1a1a; font-size: 50px; text-align: left;  line-height: 100%;}",
                            "width": 800,
                            "height": 300
                        },
                        "start": 9.5,
                        "length": 3.1,
                        "offset": {
                            "x": 0.16,
                            "y": -0.05
                        },
                        "transition": {
                            "in": "slideLeft",
                            "out": "fade"
                        }
                    },
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>$18.90</p>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #FFFF0000; font-size: 90px; text-align: left;  line-height: 100%;}",
                            "width": 800,
                            "height": 100
                        },
                        "start": 9.5,
                        "length": 3.1,
                        "offset": {
                            "x": 0.16,
                            "y": -0.25
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>&nbsp;</p>",
                            "width": 450,
                            "height": 450,
                            "background": "#FF0000"
                        },
                        "start": 9,
                        "length": 3,
                        "position": "bottom",
                        "offset": {
                            "x": -0.25
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>&nbsp;</p>",
                            "width": 900,
                            "height": 800,
                            "background": "#FFFFFF"
                        },
                        "start": 9,
                        "length": 3.5,
                        "position": "right",
                        "offset": {
                            "x": -0.1
                        },
                        "transition": {
                            "out": "slideUp"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "luma",
                            "src": "https://templates.shotstack.io/basic/asset/video/luma/circles/circle-expand-left.mp4"
                        },
                        "start": 12,
                        "length": 2
                    },
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.ap-southeast-2.amazonaws.com/backgrounds/bg-aviary-1.jpg"
                        },
                        "start": 9,
                        "length": 4,
                        "effect": "zoomIn"
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.ap-southeast-2.amazonaws.com/images/dish4.png"
                        },
                        "start": 12,
                        "length": 3.5,
                        "fit": "contain",
                        "scale": 0.35,
                        "effect": "zoomIn",
                        "offset": {
                            "x": 0.25
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Toast</p>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #11000000; font-size: 260px; text-align: left; }",
                            "width": 800,
                            "height": 300
                        },
                        "start": 12.4,
                        "length": 3.1,
                        "position": "topRight",
                        "offset": {
                            "x": -0.05
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Smashed Avo Toast</p>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #ff6600; font-size: 140px; text-align: left; line-height: 70%; }",
                            "width": 800,
                            "height": 280
                        },
                        "start": 12.5,
                        "length": 3,
                        "offset": {
                            "x": -0.16,
                            "y": 0.25
                        },
                        "transition": {
                            "in": "slideLeft",
                            "out": "fade"
                        }
                    },
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>Slice of toasted bread with avocado, house dressing, egg to taste and watercress leaves.</p>",
                            "css": "p { font-family: 'Barlow Regular'; color: #FF1a1a1a; font-size: 50px; text-align: left;  line-height: 100%;}",
                            "width": 800,
                            "height": 300
                        },
                        "start": 12.5,
                        "length": 3.1,
                        "offset": {
                            "x": -0.16,
                            "y": -0.05
                        },
                        "transition": {
                            "in": "slideLeft",
                            "out": "fade"
                        }
                    },
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>$18.90</p>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #FFFF0000; font-size: 90px; text-align: left;  line-height: 100%;}",
                            "width": 800,
                            "height": 100
                        },
                        "start": 12.5,
                        "length": 3.1,
                        "offset": {
                            "x": -0.16,
                            "y": -0.25
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>&nbsp;</p>",
                            "width": 450,
                            "height": 450,
                            "background": "#FF0000"
                        },
                        "start": 12,
                        "length": 3,
                        "position": "bottom",
                        "offset": {
                            "x": 0.25
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<p>&nbsp;</p>",
                            "width": 900,
                            "height": 800,
                            "background": "#FFFFFF"
                        },
                        "start": 12,
                        "length": 3.5,
                        "position": "left",
                        "offset": {
                            "x": 0.1
                        },
                        "transition": {
                            "in": "slideUp",
                            "out": "fade"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "luma",
                            "src": "https://templates.shotstack.io/basic/asset/video/luma/circles/circle-expand.mp4"
                        },
                        "start": 15,
                        "length": 2
                    },
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.ap-southeast-2.amazonaws.com/backgrounds/bg-aviary-1.jpg "
                        },
                        "start": 12,
                        "length": 4,
                        "effect": "zoomIn"
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.ap-southeast-2.amazonaws.com/logos/contemporary-color-black.png"
                        },
                        "start": 15,
                        "length": 4,
                        "fit": "none",
                        "scale": 0.8,
                        "offset": {
                            "y": 0.1
                        },
                        "transition": {
                            "in": "slideUp"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "html",
                            "html": "<span>736 Brockton Avenue, Abington, MA 2351</span><br><span>548-500-5223</span>",
                            "css": "p { font-family: 'Barlow ExtraBold'; color: #FF1a1a1a; font-size: 50px; text-align: center;} span { font-family: 'Barlow Regular'; color: #FF1a1a1a; font-size: 50px; text-align: center;}",
                            "width": 600,
                            "height": 300
                        },
                        "start": 15.8,
                        "length": 3.2,
                        "offset": {
                            "y": -0.2
                        },
                        "transition": {
                            "in": "slideUp"
                        }
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.ap-southeast-2.amazonaws.com/backgrounds/bg-aviary-1.jpg "
                        },
                        "start": 15,
                        "length": 4,
                        "effect": "zoomIn"
                    }
                ]
            }
        ]
    },
    "output": {
        "format": "mp4",
        "resolution": "1080"
    }

};

const opt = {
    "method": "PUT",
    "headers": {
         'Content-Type':'application/json',
         'Accept':'application/json',
         'x-api-key':'**********************************'
    },
    "payload": JSON.stringify(updateTemp)
};

function uPdateTemplate() {
  const res = UrlFetchApp.fetch(link, opt);
  console.log(res.getContentText());
}

--------------------

const url = "https://api.shotstack.io/v1/templates/render";

const payload = {
  id: "36158755-b022-4f63-b438-d2a123160dae",
  merge: [
    {
      find: "name",
      replace: "RestaurentPost"
    }
  ]
};

const options = {
    "method": "post",
    "headers": {
        "Content-Type": "application/json",
        "x-api-key": "XXXXXXXXXXXXXXXXXXXXXXX"
    },
    "payload": JSON.stringify(payload)
};

function render() {
  const response = UrlFetchApp.fetch(url, options);
  console.log(response.getContentText());
}

Re-Hi :frowning_face: Any idéa how to solve this Problem .

thank You

Thanks for the bump I completely missed your last reply.

I checked your code and template and you appear to want to replace a {{name}} variable in the template.

const payload = {
  id: "36158755-b022-4f63-b438-d2a123160dae",
  merge: [
    {
      find: "name",
      replace: "RestaurentPost"
    }
  ]
};

However your variable doesn’t contain a merge variable. If you wanted to declare that variable in your template you could add it as follows:

{
      "clips": [{
        "asset": {
          "type": "html",
          "html": "<p>{{name}}</p>",
          "css": "p { font-family:'Barlow ExtraBold'; color: #FFFFFF; font-size: 68px; text-align: center; }",
          "width": 800,
          "height": 140
        },
        "start": 0.8,
        "length": 2.2,
        "offset": {
          "y": -0.13
        },
        "transition": {
          "in": "slideUp",
          "out": "fade"
        }
      }]
    }

This will allow you to run the code you’re using and replace the {{name}} variable with the contents of the replace property; in this case RestaurentPost.