Action

Send to Capacities

Posted by XTY, Last update 5 months ago

action to send draft to capacities daily notes

Steps

  • script

    
    // Create a credential object
    
    let credential = Credential.create("Capacities");
    
    // Add password field for Capacities access token
    credential.addPasswordField("access_token", "API Token");
    
    // Add text field for capacities space id
    credential.addTextField("space_id", "Space Id");
    
    // Authorize the credential object
    credential.authorize();
    
    // Get the Capacities Daily Note URL, access token and space id from the credential object
    let endpoint = "https://api.capacities.io/save-to-daily-note";
    let accessToken = credential.getValue("access_token");
    let spaceId = credential.getValue("space_id");
    
    // Get the content of the draft
    let content = draft.content;
    let note = "";
    
    // Check if the content is not empty
    if (content.length > 0) {
        // Create an HTTP object
        var http = HTTP.create();
    
        // Send a POST request to the Capacities API with the content
        var response = http.request({ 
        	"url": endpoint, 
        	"method": "POST", 
        	"data": { 
        	 	"mdText": content, 
        	 	"spaceId": spaceId,
        		},
        	"headers": { 
        		"Content-Type": "application/json", 
        		"Authorization": "Bearer " + accessToken 
        		}
        	});
    };
    
    // Log the response status code
    console.log("Response: " + response.statusCode);
    
    // Check if the response status code is not 200 or 202
    if (response.statusCode != 200 && response.statusCode != 202) {
        // Fail the context
        context.fail();
    }

Options

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