Can a platform programmatically get a user's Glitch URL?


#1

It looks like the public url link / copy button was recently taken out of the project menu.

Unfortunately this makes a previously painful problem now a bit more painful:

After sending a user to Glitch with the Button API, how how can I programatically get the URL of their newly created project?

This “copy public URL” link was my best workaround for onboarding users.

Why need this?

In an OAuth2 handshake, the platform that issues the keys needs to know the URL authorizing app. Same with an application that processes webhooks. The public URL is a necessary config value for many platform scenarios.

I made another suggestion to let the developer pass a random subdomain as part of the environment.

The docs actually imply that this can be done:

PROJECT_DOMAIN – Contains your project’s name, useful for programmatically specifying your project’s URL

However, passing PROJECT_DOMAIN in the button API does not set the subdomain. The “copy public URL” field was an ok workaround.

If Glitch is being used to extend other products there must be a programmatic way to hand off the the public URL of the project. Making one-click setups for platforms would be so much more awesome.

Does anyone happen to have a workaround?

EDIT:
To give some additional context, here is the Facebook Messenger Glitch quickstart.

Note the language about copying the public URL.

But imagine if there was just a single “Remix In Glitch” button that passed the client id, client secret, and subdomain. It would be a one-click FB Messenger app. No setup required.

EDIT:
I removed the link to our example project as it’s no longer relevant.


#2

It wasn’t removed, it just moved to the share menu.

The project_domain env value lets you use the Glitch.me sub-domain for an app in the app’s code without having to know it, rather than set your own value for it. I’ll rephrase this in the docs so it’s clearer.

But here’s an example of it in use: https://glitch.com/edit/#!/github-oauth

Allowing a third-party to specify a project name is problematic in scenarios where it’s already taken etc. Perhaps getting a return value with the new project’s name might be useful?


#3

Thanks, Gareth. Makes sense about subdomain name collisions.

Perhaps getting a return value with the new project’s name might be useful?

Yes, any method of returning that programmatically would be great.

For now, we continually running a callback function within the first ~10 minutes of the life of the Glitch project that posts a token (as a lookup key) and the projects’s public URL to an endpoint on our end. So, we have our on-click Glitch link after all.

Another idea: maybe an eventual Glitch API could expose the renaming functionality shown in the UI:

Yet another idea: maybe the URL can only be accessed with embedded Glitch projects, similar to RunKit.

Glitch is already so awesome, and our needs are solved for now. Just throwing ideas out there from the perspective of a platform trying to optimize Glitch onboarding for our developers. Hope it helps.


#4

There are two ways to create a project and populate the .env file while remixing right now. You can make a link like this:

https://glitch.com/edit/#!/remix/<base-name>?<var1>=<value1>&<var2=value2>

The other way is to POST to a URL like this:

https://api.glitch.com/projects/<base-name>/remix

In that case, you should send a JSON body with the environment vars like this:

{
  env:
    var1: "value1"
    var2: "value2"
}

The POST endpoint returns the join link for the project right now. We might be able to change that to return a JSON object that also includes the domain. Off the top of my head, I don’t remember how many things are using the returned data.


#5

Thanks, Tim. I created an example project. It returns:

{
  "joinLink": "https://glitch.com/edit/#!/join/5030acdb-3676-4c32-b662-aea5111aaaaa"
}

This was the request:

$.ajax({
  type: 'POST',
  url: 'https://api.glitch.com/projects/remix-example-with-post/remix',
  data: {
    env: {
      env1: 'test',
      env2: 'testing' 
    }
  }
}).done(function(res) {
  console.log('post results', res);    
})

If this also returned the project domain it would be perfect for our use-case. It also sounds like the cleanest of the implementation ideas above.

Our “One Click Glitch” setup would made be far less complicated.


Edit: My code as above returned the “join” link as expected, but when adding contentType: "application/json; charset=utf-8" I started getting a CORS error.

$.ajax({
  type: 'POST',
  url: 'https://api.glitch.com/projects/remix-example-with-post/remix',
  data: {
    "env": {
      "env1": 'test',
      "env2": 'testing' 
    }
  },
  // contentType: "application/json; charset=utf-8",  // <--- Creates CORS Error
  dataType: "json"
}).done(function(res) {
  console.log('post results', res);    
});

It may be on my end. I don’t have time to debug, but wanted to the latest progress.

Also, I noticed the Glitch Project does not actually initialize until I visit the join URL. If this method was implemented, it would be ideal to let the developer pass a flag or something to initialize immediately.