Programmatically set env file? Per-student setup


#1

Each of our students has their own set of credentials.

I’d like them to run and see code in Glitch, and then have the opportunity to remix it themselves.

Option 1 can be done now:

  1. Glitch project looks for the student’s credentials in either env variables or query parameters.
  2. My site runs the Glitch URL with the query parameters set for the student’s credentials.
  3. If the student wants to remix, they login/create account, remix, then set up an env file with their own credentials.

Works but step 3 is a bit involved.

Option 2 or better would be preferred:

  1. My site somehow (Glitch API?) creates an anonymous remix of the project and sets the env file to the student’s credentials.
  2. The student views the example as an anonymous Glitch user.
  3. If the student wants to remix, they simply save the project for themselves.

Thoughts?

A goal is for the students to not need a Glitch account unless they want to remix.


#2

You can populate env var values on remix from a URL, so if on your side you can add the credentials to the URL, then Option 2 should work - see https://glitch.com/help/populate-env/


#3

Excellent – so my project offers the remix button to the student (including the student’s credentials) rather than the student clicking the generic Remix button on your site.

Many thanks,
Larry


#4

Or the process starts with a Remix from my site? Does a remix work for a then anonymous user?


#5

Wherever you’re able to set the student’s credentials from. Yes, you don’t need to be logged-in to remix.


#6

If you’re going to remix programmatically, it’s better to POST to https://api.glitch.com/projects/<project-name>/remix. You can send a JSON body like:

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

It will return

{
    id: project.id,
    domain: project.domain,
    inviteToken: project.invite_token,
    joinLink: joinLink
  };

Set env when remixing from API
#7

Thanks Tom.

Do I then use the joinLink to open the new remix for the anonymous or logged in user?

Any immediate need for the id, domain, or inviteToken?

Also, when using the remix url with env settings via the url – eg “https://glitch.com/edit/#!/remix/project-name?ACCESS_TOKEN=eyJ0eXAiOid2c2e&USER_FULLNAME=Larry%20Kluger&USER_EMAIL=larry%40example.com

I noticed a possible bug: The USER_FULLNAME line in the created env file is

USER_FULLNAME=Larry Kluger

This results in an error since the env file should be

USER_FULLNAME="Larry Kluger"

Thanks again for your help and time.


#8

You would give the joinLink to the user who is going to own the new project - anyone using that link becomes a member of the project. You might want to use the domain for something - that’s the name of the new project.

I think you can probably add the quotes to the URL (either directly or maybe URL encoded), and they will be added to .env. If not, let me know and we’ll fix that.


#9

I tried the API call, but received a response body of Error remixing project. I tried twice.

Response header date: “Wed, 26 Sep 2018 18:15:11 GMT”
Response status: 200. (Not expected since the request didn’t succeed.)

Details:
POST to https://api.glitch.com/projects/docusign-send-envelope/remix
request body:

"{
    "env": {
        "ACCESS_TOKEN": "eyJ0eXAiOiJNVCIsImFsZyI6IlJTMjU2xxxxxxxx...xxxx",
        "ACCOUNT_ID": "b124a74b-faa8-46f7-a55e-9xxxxxxxx",
        "USER_FULLNAME": "Larry Kluger",
        "USER_EMAIL": "larry@example.com"
    }
}"

#10

Using " around the environment variables sent via query parameters worked.

Eg https://glitch.com/edit/#!/remix/project_name?USER_FULLNAME="Larry%20Kluger"

You may want to update your page https://glitch.com/help/populate-env/