Action

Send to Memos [v2]

Last update 8 days ago

UPDATES

8 days ago

fix error info

For memos version >= 0.22.0
action to send draft to memos, a selfhost memo application, for more information,checkout https://usememos.com/

Steps

  • script

    /*
      Post to Memos with Access Token
      API: POST /api/v1/memos (Memos v1 API, https://usememos.com/docs/api/latest)
      Auth: Authorization: Bearer <personal access token> (memos_pat_ prefix)
    */
    
    // Create a credential object
    let credential = Credential.create("Memos Instance URL & Access Token",
    `URL example: https://demo.usememos.com
    
    Get Access Token from your memos instance: "Settings > My Account > Create"`);
    
    // Add URL field for Memos instance URL
    credential.addURLField("memos_instance", "Memos Instance URL");
    
    // Add password field for Memos access token
    credential.addPasswordField("memos_access_token", "Memos Access Token");
    
    // Authorize the credential object
    credential.authorize();
    
    // Get the Memos instance URL and access token from the credential object
    let endpoint = credential.getValue("memos_instance") + "/api/v1/memos";
    let accessToken = credential.getValue("memos_access_token");
    
    // Get the content from draft
    let content = draft.content.trim();
    
    // Check if the content is not empty
    if (content.length > 0) {
        // Create an HTTP object
        let http = HTTP.create();
    
        // Send a POST request to the Memos API with the content
        // Visibility: PRIVATE | PROTECTED | PUBLIC (defaults to PRIVATE)
        var response = http.request({
            "url": endpoint,
            "method": "POST",
            "data": {
                "content": content,
                "visibility": "PRIVATE"
            },
            "headers": {
                "Content-Type": "application/json",
                "Authorization": "Bearer " + accessToken
            },
            "timeout": 60
        });
    
        // HTTPResponse.success is true for any 2xx status code
        if (response.success) {
            // Parse the created memo for an optional confirmation message
            let memo = JSON.parse(response.responseText);
            console.log("Memo created: " + memo.name);
            app.displaySuccessMessage("Posted to Memos ✓");
        } else {
            // Surface the failure: HTTP error or network/request level error
            let detail = response.responseText || response.error || "No response body";
            console.log("Response: " + response.statusCode + " " + detail);
            alert("Failed to post to Memos", "Status: " + response.statusCode + "\n\n" + detail);
            context.fail();
        }
    } else {
        alert("Empty Draft", "Nothing to post.");
        context.fail();
    }

Options

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