Pre-populate deploy button variables via query string

I was speaking with @philhawksworth over on Twitter about a handy little Netlify trick for deploy buttons.

It would be super useful if along with the repo name, you could specify additional query string params for the field values to be used on the deploy form.

There are cases where you have access to the values (for instance, imagine you’re logged into a Dashboard and have a list of deploy buttons, where one of the fields was the current users ID, name or API key)

If this is currently possible, someone please let me know :rocket: and if not, please consider this request :kissing_heart:

I think this is only even close to possible today with the deploy to netlify button. Then I believe that you’re limited to what is set in the toml file, so that isn’t really super close to what you were asking for.

Were I to file a feature request for us, would you be open to doing it via the deploy button noting that you have to configure it using netlify.toml, or do you have some other proposal I should try to capture instead?

Essentially all the feature request would be asking for is the ability to pass down the query string to the form on the page.

I’m surprised this isn’t baked into any of your forms already, useful for login or reset password forms when you already know the email ahead of time and want to pre-populate the form. The same applies to the deploy screen, as it’s separate from the .toml file.

Oh, sorry, that sounds like something very different! You can of course implement the javascript to do this on the client side - take query strings and autofill fields when you render your form, and then when you submit those values will be either used as-is or as the user has edited. We can’t easily do it ourselves automagically since there are infinite ways to draw a form and it would be impossible to cover all use cases.

I thought you were talking about specifically creating a new site on Netlify which we don’t have fantastic support beyond the deploy button for templating right now.

Sorry, I must be confusing matters by explaining it further.

I indeed do mean the deploy button page as shown in my screenshot.

If I were able to provide the form values in the querystring of the above link to populate this form, that would be gold:

1 Like

great, thanks! I’ve filed a feature request to enable that and we’ll follow up in this thread if we do.

+1 to this idea. At Contentful, we’d love to use this idea for deploying frontend apps for our customers. In our case, the user is logged into Contentful, so our app knows the Space ID, Delivery API Token, and Preview API Token for the user and it’d be great if we could present the user with a Deploy to Netlify button where these environment variables are already filled out. As it is now, we present the user with the information that they then have to copy from Contentful and paste into the netlify Deploy screen.

Here’s a screenshot from Contentful where I’m installing the knowledge base app:

And this is what I get when I click the above Deploy to Netlify button. Notice the three environment variable fields need to be filled out manually by the user. Easy place to make a mistake that could be avoided.

Thanks for explaining your use case in detail, @cachrisman! I’ve brought this different feature request to our product team for their consideration.

Actually, it turns out there’s a hidden feature that allows you to do this. You can add variables and values to the hash of the URL, with multiple values separated by &. Here’s an example URL:

Why in the hash instead of query params? Query params get sent to server logs; hashes are client-only. So you can add API tokens, etc. and they won’t show in our logs. :sparkles:

This hasn’t made it into the docs yet because we only recently learned about it.

1 Like