Converting vCard or vcf to csv

Heyy Everyone… I am trying to convert a vcf (Contact file) to csv in make. Any suggestions to do that within make?

What happens when you do

toString(data)

on the file data after you’ve downloaded it?

Please provide the output bundles of the modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.
Screenshot_2023-10-06_141025

A.

Save each bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading them here will look like this:

module-1-input-bundle.txt (12.3 KB)
module-1-output-bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

This will allow others to better assist you. Thanks!

1 Like

with toString function i receive this data :


and with text parser using key: value, i receive some details but not getting empty fields

Looks like you can use a Text Parser Match Pattern module since it’s almost plain text format.

Not Match Elements.

1 Like

That works 50%.
But problem is when i use online converter tools in csv file, i receive empty fields/columns as well. Is there something that can be done using tools> text encoder module?

Why not put in a filter on the path after the text parser to check for empty values coming in from the text parser bundles? That way you can evaluate which fields go into the converter tools module?

1 Like

Here’s a small scenario that converts the VCF string with an empty FN: key and filters that out from the final CSV. YOu can copy this to your clipboard and paste it into a new scenario.

Note that your CSV will just have 2 columns, the key and the value. If you want to actually convert each key into a column name and then each value into a component of one row that’s a completely different operation and the results of the text parse will need to be restructured into a row using some data structure manipulation.

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 1,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "vcf2.1string",
                                "value": "BEGIN:VCARD\nVERSION:2.1\nN:Gump;Forrest;;Mr.\nFN:\nORG:Bubba Gump Shrimp Co.\nTITLE:Shrimp Man\nPHOTO;GIF:http://www.example.com/dir_photos/my_photo.gif\nTEL;WORK;VOICE:(111) 555-1212\nTEL;HOME;VOICE:(404) 555-1212\nADR;WORK;PREF:;;100 Waters Edge;Baytown;LA;30314;United States of America\nLABEL;WORK;PREF;ENCODING#QUOTED-PRINTABLE;CHARSET#UTF-8:100 Waters Edge#0D#\n #0ABaytown\\, LA 30314#0D#0AUnited States of America\nADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America\nLABEL;HOME;ENCODING#QUOTED-PRINTABLE;CHARSET#UTF-8:42 Plantation St.#0D#0A#\n Baytown, LA 30314#0D#0AUnited States of America\nEMAIL:forrestgump@example.com\nREV:20080424T195243Z\nEND:VCARD"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": 0,
                            "y": 0
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "vcf2.1string",
                                "label": "vcf2.1string",
                                "type": "any"
                            }
                        ]
                    }
                },
                {
                    "id": 2,
                    "module": "regexp:GetElementsFromText",
                    "version": 1,
                    "parameters": {
                        "continueWhenNoRes": false
                    },
                    "mapper": {
                        "pattern": "##key_value_pairs",
                        "text": "{{1.`vcf2.1string`}}",
                        "delimiter": ":",
                        "strictMatchPerLine": true,
                        "specialCharsPattern": ""
                    },
                    "metadata": {
                        "designer": {
                            "x": 262,
                            "y": -1
                        },
                        "restore": {
                            "expect": {
                                "pattern": {
                                    "label": "Pair of key:value"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "continueWhenNoRes",
                                "type": "boolean",
                                "label": "Continue the execution of the route even if the module finds no matches",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "pattern",
                                "type": "select",
                                "label": "Pattern",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "##emails",
                                        "##html_tags",
                                        "##http_urls",
                                        "##ftp_urls",
                                        "##telephone_numbers",
                                        "##ipv4",
                                        "##ipv6",
                                        "##emoji",
                                        "##key_value_pairs"
                                    ]
                                }
                            },
                            {
                                "name": "text",
                                "type": "text",
                                "label": "Text",
                                "required": true
                            },
                            {
                                "name": "delimiter",
                                "type": "text",
                                "label": "Delimiter",
                                "required": true
                            },
                            {
                                "name": "strictMatchPerLine",
                                "type": "boolean",
                                "label": "Only first pair per line",
                                "required": true
                            },
                            {
                                "name": "specialCharsPattern",
                                "type": "text",
                                "label": "Special characters in the pattern"
                            }
                        ],
                        "interface": [
                            {
                                "name": "match",
                                "label": "Match",
                                "type": "any"
                            },
                            {
                                "name": "key",
                                "label": "Key",
                                "type": "text"
                            },
                            {
                                "name": "value",
                                "label": "Value",
                                "type": "text"
                            }
                        ]
                    }
                },
                {
                    "id": 4,
                    "module": "csv:CreateAggregator",
                    "version": 1,
                    "parameters": {
                        "includeHeaders": true,
                        "delimiterType": "other",
                        "newlineType": "LF",
                        "delimiter": ",",
                        "feeder": 2
                    },
                    "filter": {
                        "name": "for all non empty values",
                        "conditions": [
                            [
                                {
                                    "a": "{{2.value}}",
                                    "o": "text:notequal",
                                    "b": "{{emptystring}}"
                                }
                            ]
                        ]
                    },
                    "mapper": {
                        "key": "{{2.key}}",
                        "value": "{{2.value}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 602,
                            "y": -4,
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "parameters": {
                                "delimiterType": {
                                    "label": "Other"
                                },
                                "newlineType": {
                                    "label": "LF"
                                }
                            },
                            "extra": {
                                "feeder": {
                                    "label": "Text parser - Match elements [2]"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "includeHeaders",
                                "type": "boolean",
                                "label": "Include headers in the first row",
                                "required": true
                            },
                            {
                                "name": "delimiterType",
                                "type": "select",
                                "label": "Delimiter",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        ",",
                                        "\t",
                                        "other"
                                    ]
                                }
                            },
                            {
                                "name": "newlineType",
                                "type": "select",
                                "label": "Newline",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "LF",
                                        "CRLF"
                                    ]
                                }
                            },
                            {
                                "name": "delimiter",
                                "type": "text",
                                "label": "Delimiter character",
                                "validate": {
                                    "max": 1,
                                    "min": 1
                                },
                                "required": true
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
2 Likes

@alex.newpath Thanks for this solution…



I tried ChatGPT for better formatting and well-defined output as it gives expected results.

Does it have an API to use it in automation?