Action

Send to Mem

Posted by skyturtleio, Last update about 3 years ago

UPDATES

about 3 years ago

Removed hard coded API key and use Drafts Credentials object

Sends the draft to Mem using Mem’s API v0.

By default, the draft will arrive in your Inbox marked as “Unread”. If you would like to change these defaults, the developer docs can be found here Mem API.

You will need to set up your Mem Personal API Keys:

  • Within Mem, select “Flows”
  • Select “Configure” under “API”
  • Click “Create New API Key”
  • Enter an API Key Label (I used “Drafts”)
  • Store the API key somewhere safe e.g. 1Password

The first time you run the action, Drafts will prompt you to enter the API key you just created and stores it for later use. On subsequent runs, you will not have to enter your key.

Now you are all set up to start sending drafts directly to Mem 😎

This script uses the Credential object from the Drafts Scripting library. The documentation can be found here.

If at any point you want to delete the API key from Drafts, go to Settings > Credentials and tap “Forget” on credential you would like to delete.

If you’d like a little more background, I wrote about it here.

Steps

  • script

    // See online documentation for examples
    // https://docs.getdrafts.com/docs/actions/scripting
    
    var http = HTTP.create(); // create HTTP object
    var url = "https://api.mem.ai/v0/mems"
    var content = draft.content
    var credential = Credential.create("Mem API Key", "Personal API Key from Mem Flows")
    
    credential.addPasswordField("apiKey", "Mem Personal API Key");
    
    credential.authorize();
    
    var response = http.request({
      "url": url,
      "method": "POST",
      "data": {
        "content": content
      },
      "headers": {
        "Content-Type": "application/json",
        "Authorization": "ApiAccessToken " + credential.getValue("apiKey")
      }
    });
    
    if (response.success) {
      var text = response.responseText;
      var data = response.responseData;
    }
    else {
      console.log(response.statusCode);
      console.log(response.error);
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.