Created
February 12, 2019 00:43
-
-
Save colophonemes/219c29b265bd8e1a9ba90c2de0c7c7ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ASANA_ACCESS_TOKEN=<YOUR_ACCESS_TOKEN> | |
ASANA_PROJECT_GID=<YOUR_PROJECT_GID> | |
ASANA_CUSTOM_FIELD_GID=<YOUR_CUSTOM_FIELD_GID> | |
ASANA_WORKSPACE_GID=<YOUR_WORKSPACE_GID> | |
# relies on csv2json and jq | |
# csv2json: yarn global add csv2json | |
# jq: https://github.com/stedolan/jq | |
CSVDATA=$(csv2json -d "$1") | |
IFS=$'\n' # make newlines the only separator | |
for row in $(echo ${CSVDATA} | jq -cr '.[]'); do | |
_jq() { | |
echo ${row} | jq -r ${1} | |
} | |
# cast to JSON payload | |
SUBMITTER=$(echo ${row} | jq -r '.submitter') | |
SOURCE=$(echo ${row} | jq -r '.source') | |
read -d '' JQI << EOF | |
{ | |
data: { | |
name: .task_name, | |
notes: "Submitter - ${SUBMITTER}, Source - ${SOURCE}", | |
workspace: $ASANA_WORKSPACE_GID, | |
memberships: [{ | |
project: $ASANA_PROJECT_GID | |
}], | |
custom_fields: { | |
"$ASANA_CUSTOM_FIELD_GID": .microgenes | |
} | |
} | |
} | |
EOF | |
PAYLOAD=$(echo ${row} | jq "$JQI") | |
echo $PAYLOAD | jq '.data.task_name' | |
curl -s\ | |
-H "Authorization: Bearer $ASANA_ACCESS_TOKEN"\ | |
-H 'Content-Type: application/json' \ | |
--request POST \ | |
--data "$PAYLOAD" \ | |
https://app.asana.com/api/1.0/tasks \ | |
| jq '.data.gid' | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment