Drafts Script Reference

Credential

Credential objects can be used in actions which require the user to provide a username, password and optionally a host name, to connect to a service. By using credentials objects, actions can be written to connect to arbitrary web services without hard coding credentials into the action.

When an authorize() call is made on a credential object for the first time, the user is prompted to enter their credentials, then Drafts stores those for later use. When the action is used again, there will be no prompt required and the stored credentials will be used.

Credentials objects have unique identifiers, and a single set of user credentials can be used across actions by using the same identifier.

The user can delete those credentials at any time by visiting Settings > Credentials and tapping the “Forget” button on a service.

Credential

Examples

var credential = Credential.create("My Service", "Description of the service to appear in user prompt.");

credential.addTextField("username", "Username");
credential.addPasswordField("password", "Password");

credential.authorize();

var http = HTTP.create();
var response = http.request({
  "url": "http://myurl.com/api",
  "username": credential.getValue("username"),
  "password": credential.getValue("password"),
  "method": "POST",
  "data": {
    "key":"value"
  },
  "headers": {
    "HeaderName": "HeaderValue"
  }
});