{ "kind": "open-flow-workflow", "version": 1, "name": "Create and Update a Copper Contact", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_f304cd63d91c9a16": { "name": "Enter contact details", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "userEmail" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "name" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "phone" } ] }, "n_1699d8579279a751": { "inputs": { "userEmail": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_f304cd63d91c9a16", "output": "userEmail" } ] }, "name": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_f304cd63d91c9a16", "output": "name" } ] }, "email": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_f304cd63d91c9a16", "output": "email" } ] }, "phone": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_f304cd63d91c9a16", "output": "phone" } ] } }, "name": "Prepare contact details", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "userEmail" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "name" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "phone" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "userEmail" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "name" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "phone" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "create" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "update" } ], "name": "Prepare contact details", "moduleId": "n_78b9c56736b1fb9a", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_97b0c4b63d10ac78": { "inputs": { "url": { "kind": "value", "value": "https://api.copper.com/developer_api/v1/people" }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1699d8579279a751", "output": "create" } ] }, "header.X-PW-Application": { "kind": "value", "value": "developer_api" }, "header.X-PW-UserEmail": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1699d8579279a751", "output": "userEmail" } ] }, "auth.token": { "kind": "unset" } }, "name": "Create person", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-PW-Application" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-PW-UserEmail" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Create person", "executor": { "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [ "X-PW-Application", "X-PW-UserEmail" ] }, "bodyFormat": "json", "authentication": { "type": "apiKey", "name": "X-PW-AccessToken", "in": "header" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_3854d7e8e866ee0b": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_97b0c4b63d10ac78", "output": "body" } ] } }, "name": "Identify person", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" } ], "outputs": [ { "jsonSchema": { "type": "integer", "minimum": 1 }, "nullable": false, "handle": "id" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" } ], "name": "Identify person", "moduleId": "n_8849ce6a50a539a2", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_40a96a0941280e9a": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3854d7e8e866ee0b", "output": "url" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1699d8579279a751", "output": "update" } ] }, "header.X-PW-Application": { "kind": "value", "value": "developer_api" }, "header.X-PW-UserEmail": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1699d8579279a751", "output": "userEmail" } ] }, "auth.token": { "kind": "unset" } }, "name": "Update work phone", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-PW-Application" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-PW-UserEmail" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Update work phone", "executor": { "method": "PUT", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [ "X-PW-Application", "X-PW-UserEmail" ] }, "bodyFormat": "json", "authentication": { "type": "apiKey", "name": "X-PW-AccessToken", "in": "header" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_4467eb893a9d2948": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_40a96a0941280e9a", "output": "body" } ] }, "id": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3854d7e8e866ee0b", "output": "id" } ] } }, "name": "Confirm update", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer", "minimum": 1 }, "nullable": false, "handle": "id" } ], "outputs": [ { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "ok" } ], "name": "Confirm update", "moduleId": "n_47fabe889df568a4", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_7c9f7f2de8a6c76b": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3854d7e8e866ee0b", "output": "url" } ] }, "header.X-PW-Application": { "kind": "value", "value": "developer_api" }, "header.X-PW-UserEmail": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1699d8579279a751", "output": "userEmail" } ] }, "auth.token": { "kind": "unset" } }, "name": "Read person", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-PW-Application" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "header.X-PW-UserEmail" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Read person", "executor": { "method": "GET", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [ "X-PW-Application", "X-PW-UserEmail" ] }, "bodyFormat": "none", "authentication": { "type": "apiKey", "name": "X-PW-AccessToken", "in": "header" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_0ecfe92602d69311": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7c9f7f2de8a6c76b", "output": "body" } ] }, "id": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3854d7e8e866ee0b", "output": "id" } ] }, "email": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1699d8579279a751", "output": "email" } ] }, "phone": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1699d8579279a751", "output": "phone" } ] } }, "name": "Verify person", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer", "minimum": 1 }, "nullable": false, "handle": "id" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "email" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "phone" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "person" } ], "name": "Verify person", "moduleId": "n_b04de57e70ad4c1a", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_5dabc4dd3c961a4f": { "name": "Copper person", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "person" } ], "outputMappings": { "person": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0ecfe92602d69311", "output": "person" } ] } } } }, "edges": [ { "source": "n_f304cd63d91c9a16", "target": "n_1699d8579279a751" }, { "source": "n_1699d8579279a751", "target": "n_97b0c4b63d10ac78" }, { "source": "n_97b0c4b63d10ac78", "target": "n_3854d7e8e866ee0b" }, { "source": "n_3854d7e8e866ee0b", "target": "n_40a96a0941280e9a" }, { "source": "n_40a96a0941280e9a", "target": "n_4467eb893a9d2948" }, { "source": "n_4467eb893a9d2948", "target": "n_7c9f7f2de8a6c76b" }, { "source": "n_7c9f7f2de8a6c76b", "target": "n_0ecfe92602d69311" }, { "source": "n_0ecfe92602d69311", "target": "n_5dabc4dd3c961a4f" } ] } }, "modules": { "n_78b9c56736b1fb9a": { "name": "Prepare contact details", "imports": [], "source": "export default function setup({userEmail,name,email,phone}){if(typeof userEmail!=='string'||!/^\\S+@\\S+\\.\\S+$/.test(userEmail.trim())||typeof email!=='string'||!/^\\S+@\\S+\\.\\S+$/.test(email.trim()))throw Error('Enter valid account and contact emails');if(typeof name!=='string'||!name.trim()||typeof phone!=='string'||!phone.trim())throw Error('Enter a name and phone');return{userEmail:userEmail.trim(),name:name.trim(),email:email.trim(),phone:phone.trim(),create:{name:name.trim(),emails:[{email:email.trim(),category:'work'}]},update:{phone_numbers:[{number:phone.trim(),category:'work'}]}};}\n" }, "n_8849ce6a50a539a2": { "name": "Identify person", "imports": [], "source": "export default function created({body}){const id=body?.id;if(!Number.isSafeInteger(id)||id<1)throw Error('Copper did not return a person ID');return{id,url:'https://api.copper.com/developer_api/v1/people/'+id};}\n" }, "n_47fabe889df568a4": { "name": "Confirm update", "imports": [], "source": "export default function updated({body,id}){if(!body||body.id!==id)throw Error('Copper did not confirm the same person');return{ok:true};}\n" }, "n_b04de57e70ad4c1a": { "name": "Verify person", "imports": [], "source": "export default function result({body,id,email,phone}){if(!body||body.id!==id||!Array.isArray(body.emails)||!body.emails.some(x=>x.email===email&&x.category==='work')||!Array.isArray(body.phone_numbers)||!body.phone_numbers.some(x=>x.number===phone&&x.category==='work'))throw Error('Copper did not return the expected person');return{person:body};}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }