Invoice Received from Outlook -> Extract Data with Anthropic -> Create In Priority
13 min
this guide will walk you through the smooth setup process, enabling efficient invoice management by automatically capturing an email attachment in outlook , extracting its data using claude of anthropic connection, and inserting the details as a new transaction invoice record into the priority database prerequisites before you begin, ensure the following connections are established connection between engini and priority learn how to connect priority to engini https //help engini ai/priority erp#connecting engini to priority erp connection between engini and outlook learn how to connect outlook to engini https //help engini ai/outlook#add a connection to outlook in engini connection between engini and anthropic claude learn how to connect anthropic to engini https //help engini ai/anthropic#connecting engini to anthropic create a new workflow to learn how to create a workbook, click on workflows https //help engini ai/create workflow add a check for new emails trigger to get started, add check for new emails trigger activity of outlook mailbox choose the connection of your outlook account starting (utc) set the starting (utc) date and time this defines when the workflow should begin checking for emails recur every choose how often the workflow should run by setting the recur every fields (e g , set to 30 minute ) filters to ensure the workflow only triggers on emails that contain an invoice attachment, you must configure the following filters add filters repeat on step 5 to add more conditions in addition to the status condition if necessary you can populate the value field in one of the following options static value – number / string when using strings, you need to surround them with single quotes (‘) expression – using functions https //help engini ai/enginis functions and/or previous activity properties and/or static values (using the tooltip that opens when clicking on the field) sort & filter now we want to filter the emails located in outlook, that are sent from the specific client choose sort & filter action of engini into your workflow data list – add dynamically the data base representing the list of emails from the previous outlook trigger into the data list input field add filter choose add filter in the filter section field select the field to filter by, which is from filter operator select the comparator, which in this case is equals enter the specific email address of the client/vendor you want to process initialize variable we want to initialize a variable to store the data extracted from the create messages activity response, this will be useful for later purpose choose initialize variable action of engini into your workflow name – give your variable a name (e g , message output) type – choose in the dropdown options for type the string type, the message output will be in form of a text value – leave it empty for each loop now that we have filtered the list to include only the relevant emails, we must iterate through them one by one to process the attachment and extract the invoice data choose the for each loop action of engini and insert it into your workflow add dynamically the data output from the previous sort & filter step into the data list input field compose string the compose string action is used here to define the exact instructions (the prompt ) for the ocr/ai service (claude) on what to extract from the invoice attachment choose the compose string action of engini and insert it as the first step inside the for each loop optional – click the action title (or the three dots menu) and rename the block from compose string to prompt to better reflect its function in defining the ai task input paste the detailed instructions (the prompt ) for the ocr/ai engine example of input field content the content below defines the ai’s role and mandates the extraction of required fields into a strict json format using the specified hebrew keys build the create a message structure add an object array variable to define the structure (schema) for the temporary array that will hold the extracted invoice data choose the initialize object array action of anthropic claude and insert it into your workflow variable name enter “content” this is the name you will use to reference this temporary array later in the workflow object element type this defines the structure of each item within the array note you can perform the append to object variable step directly inside initialize object array using add field – fewer actions, faster flow this is for one object in this example we choose to show you the append activity too add an append to object array action of anthropic claude to take the attachment content from the filtered email and append it to the content array this prepares the file data to be sent to the ocr for extraction variable – select the array variable you initialized in the previous step (e g , content) type – select the “document” type fields and define the following three crucial fields for sending the file content media type set the field name to media type and the value application/json (as the invoice is expected to be a pdf) source type set the field name to source type and the value to base64 (as this is the required encoding for the ocr) source data set the field name to source data dynamically choose the data base representing the attachment content from the outlook step into the value field (e g , 14 attachments\[] content(base64)) add an append to object array action of anthropic claude to define the text instructions that accompany the pdf file sent for processing variable – select the array variable you initialized in the previous step (e g , content) type – select the “text” type fields and define the field to hold the instructions set the field name to text use the engini function tojsonstring() wrapped around the output of the prompt step dynamically choose the output of the compose string (“prompt”) add an initialize object array action to create the array that will hold the final structured request payload for the ocr service variable name enter “messages” object element type select the object “messages” fields twice to configure the two required elements of the message role set the first field name to role and the value to user content set the second field name to contents\[] and map the object array variable that we created for content in the previous steps this is the final action that sends the structured request (the file and the instructions) to the claude ocr engine for data extraction and receives the structured json output choose the create messages action of anthropic claude and insert it into your workflow model select or enter the specific anthropic claude model optimized for complex document understanding and json output we recommend using the latest high performance model suggested model claude opus 4 8 (or the specific version you are licensed for) messages\[] the object array initialized in the previous step named messages max tokens insert the maximum length allowed for the response from the ocr service (not including the input size) explanation this value determines how long the resulting json output can be since you are expecting a structured list of line items, ensure this value is high enough a typical starting recommendation is 20000 ,which is generally sufficient for detailed json extraction set variable stay in the same for each loop, and now add the set variable action to it we want to update the value inside of the variable we created before the loop choose set variable https //help engini ai/transform and format#set variable action of engini into your workflow name in the dropdown options choose the name of the variable you named before (e g , message output https //app archbee com/docs/ixqqblwfxopjg0nave78y/idt 4wxm6f7fgfjrr8kf#rxmfz ) value – choose the engini function first () https //help engini ai/enginis functions#first function and wraaped it around the content text you can find it dynamically inside the create messages >content \[] > text invoice object after the create message request returns its response, the output often contains extra text or characters outside the main json object this step uses engini’s functions to isolate the clean json for easy mapping in later steps choose the initialize variable action of engini and insert it into your workflow click the action title and rename it to invoice object for clarity name – invoice object type – choose object value insert the following formula to locate and extract only the valid json string slice () https //help engini ai/enginis functions#slice function – extracts the clean string between those two points, ensuring only the valid json data is saved as the invoice object indexof () https //help engini ai/enginis functions#indexof function – finds the position where the json object officially begins lastindexof () https //help engini ai/enginis functions#lastindexof function – finds the position where the json object ends parse json/xml the data saved in the previous step (invoice object) is currently a text string this step converts that string into a native object structure so engini can access individual fields (like “invoice date” or “total amount”) using data pills choose the parse json / xml action of engini and insert it into your workflow content – dynamically map the output variable from the previous step (e g , invoice object) generate output schema paste a sample of the exact json structure that you defined in the prompt step engini will analyze the sample and display the output structure in the response body structure panel this makes the individual fields available for mapping to priority in the final steps create in priority this is the final step where the extracted and structured invoice data is inserted directly into priority, completing the automation workflow choose the create action of your priority connection and insert it into your workflow select the appropriate priority erp form or table where the invoice record should be created (e g , “חשבונית עסקה” / “transaction invoices” or the relevant purchase invoice form) click add field to map the data from the messages output to the necessary priority fields the structure is always priority field name –> value from jsonobject