Action

⬆️ Reflect

Posted by Sam Levan, Last update 11 months ago

Send Draft note to Reflect app

Steps

  • script

    /** ============================================================================
     * Drafts to Reflect
     * 
     * Send a draft to Reflect app
     * 
     * @link https://openpm.ai/apis/reflect
     *
     * @version   0.0.1
     * ========================================================================== */
    
    
    const credential = Credential.create(
    	'Reflect',
    	"Create a new oAuth client at https://reflect.app/developer/oauth and then get a token by clicking \"generate access token\""
    );
    
    
    
    credential.addPasswordField('access_token', 'Access Token');
    credential.addPasswordField('graph_id', 'Graph Id');
    
    
    credential.authorize();
    
    const access_token = credential.getValue('access_token');
    const graph_id = credential.getValue('graph_id');
    
    
    if (!access_token) {
    	context.fail('An access token is needed');
    	credential.addPasswordField('access_token', 'Access Token');
    	credential.authorize();
    }
    if (!graph_id) {
    	context.fail('An Graph Id is needed');
    	credential.addPasswordField('graph_id', 'Graph Id');
    	credential.authorize();
    }
    
    
    const http = HTTP.create(); // create HTTP object
    
    const response = http.request({
    	// create the request
    	url: `https://reflect.app/api/graphs/${graph_id}/daily-notes`,
    	method: 'PUT',
    	encoding: 'json',
    	data: {
    		date: draft.createdAt.toString("yyyy-MM-dd"),
    		text: draft.content,
    		transform_type: "list-append",
    		list_name: "Drafts Notes",
    	},
    	headers: {
    		Authorization: `Bearer ${access_token}`,
    		"Content-Type": "application/json",
    	}
    });
    
    if (response.success) {
    	let success = JSON.parse(response.responseText);
    	console.log(JSON.stringify(success))
    
    	if (!success.success) {context.fail();}
    
    } else {
    	const errorMsg = `${response.statusCode}: ${response.error}, ${response.responseText}`;
    	context.fail(errorMsg);
    }
    

Options

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