mailjet / api-documentation

Mailjet API Guides
https://dev.mailjet.com/guides
22 stars 25 forks source link

Contact meta values sent via API are transformed to lowercase #20

Closed franz-josef-kaiser closed 6 years ago

franz-josef-kaiser commented 6 years ago

Situation

We noticed that the values for contact meta data get lower cased, when sent via the API. Condition: This happened when adding new contact meta data the via /contactmetadata ressource (API endpoint). It also happens, when setting values for a single contacts meta data. Problem: This makes it impossible to use the data in a campaign or in marketing automation. We write German and English E–Mails, so we need upper cased values as well (goes for English as well, w.g. City names).

Expected Result

When add a new contactmetadata property (or a value), the string would be expected to get persistent "as sent".

Actual Result

How to reproduce

  1. Set up a new directory named contactmetadata.

  2. Add a new file: {name|titel|foo}.json.

    $ # fs structure
    -\ contactmetadata
      |- name.json
      |- titel.json
      |- ….json
    contact-metadata-create.sh
  3. Add a new (bash|shell) file: contact-metadata-create.sh.

  4. Add a new file named mjapikey (without extension) and fill it with your API key + private key, comma separated.

  5. Add a new file named name.json to the /contactmetadata directory with the following contents:

    {
        "Name": "name",
        "Datatype": "str",
        "Namespace": "static"
    }
  6. Install jq for human readable JSON output in your CLI. Or install json_pp (and change below script accordingly).

  7. Add the following contents to the shell script:

    #!/usr/bin/env bash
    DATA="$(pwd)/${2}"
    
    # Single file:
    if [[ -f $DATA ]]; then
        curl -sX POST https://api.mailjet.com/v3/REST/contactmetadata \
            --user "${1}" \
            --header 'Content-Type: application/json' \
            -d @${DATA} |jq
    # Directory of meta data JSON definitions:
    else
        CONFIG="${DATA}/*.json"
        for file in $CONFIG
        do
            echo "\n --------------------"
            echo " *CONFIG:* ${file}"
            jq '.' ${file}
            echo " *REQUEST:* "
            echo " *RESPONSE:* "
            curl -sX POST https://api.mailjet.com/v3/REST/contactmetadata \
                --user "${1}" \
                --header 'Content-Type: application/json' \
                -d @${file} |jq
        done
    fi
    exit 1
    1. Call the script on the command line. It will loop through all JSON files (each is a single contact meta data/ property definition for one [sub]account) in your contactmetadata folder
      $ sh contact-metadata-create.sh $(cat mjkey) contactmetadata
ngarnier commented 6 years ago

I don't understand, is your issue is that a contact property key is case-lowered, or that the value assigned to that property is case-lowered?

Because we do lower case contact properties, but the contact property key won't be used in the content any way, only the value will be printed out (and we don't lower case assigned values). In your example, the value of your contact property is lower case, so it's pretty normal that when you use it it's lower case as well?

i.e if you create a contact property city with the value Paris, when you use it in an email with {{var:city}}, it will be replaced with Paris, not paris.

franz-josef-kaiser commented 6 years ago

@ngarnier while trying to put up the second test case, we noticed that the bug was on our side. Explanation: The meta data gets sent from a legacy application that only allows configuration through the user interface. We did not notice an option that was ticked, that lower cased the values on our end. As the calls are quite similar, we wrongly assumed that this is the same issue for both cases, so we took the test case from the script we use to set up each sub-account. Apologies!

ngarnier commented 6 years ago

No worries, glad you found the issue on your end 👍