Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Created January 21, 2025 19:22
Show Gist options
  • Select an option

  • Save TiloGit/064cfd5e4be4f132e0eb123860d2d674 to your computer and use it in GitHub Desktop.

Select an option

Save TiloGit/064cfd5e4be4f132e0eb123860d2d674 to your computer and use it in GitHub Desktop.

Revisions

  1. TiloGit created this gist Jan 21, 2025.
    30 changes: 30 additions & 0 deletions copy-box-template.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #########################
    ##login to source box account
    boxaccesstoken=$(python /mnt/c/myscripts/box-admin-scripts/box-login-read-json-dynamic.py --jsonpath /mnt/c/myscripts/box-admin-scripts/box-demo-old.json)
    ##read and copy metadata template to other box account
    myTemplateName="purchaseRequisition"

    ##get source metadata def.
    sourceJson=$(curl -s -X GET "https://api.box.com/2.0/metadata_templates/enterprise/$myTemplateName/schema" \
    -H "Authorization: Bearer $boxaccesstoken")

    ##remove id and other fields not needed for new template creation
    #echo $sourceJson | jq 'del(.id, .type, .fields[].id , .fields[].options[]?.id)'
    modsourceJson=$(jq 'del(.id, .type, .fields[].id , .fields[].options[]?.id)' <<< "$sourceJson" )
    modsourceJson2=$(jq '.scope = "enterprise"' <<< "$modsourceJson" )

    #echo $modsourceJson2 | jq .

    ##now login to new box account and apply.
    boxaccesstoken=$(python /mnt/c/myscripts/box-admin-scripts/box-login-read-json-dynamic.py --jsonpath /mnt/c/myscripts/box-admin-scripts/box-demo-new.json)

    #create metadata template copy
    curl -X POST "https://api.box.com/2.0/metadata_templates/schema" \
    -H "Authorization: Bearer $boxaccesstoken" \
    -H "Content-Type: application/json" \
    --data "$modsourceJson2"
    ###end of create metadata template

    ##check new metadata templates properties (to csv)
    curl -s -X GET "https://api.box.com/2.0/metadata_templates/enterprise/$myTemplateName/schema" \
    -H "Authorization: Bearer $boxaccesstoken" | jq -r '.fields[] | [.displayName, .key, .type, .hidden] | @csv'