Created
May 31, 2023 03:09
-
-
Save drewgillson/53a2a9102e907cdb99a57445af81a541 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| TOKEN=$(gcloud auth application-default print-access-token) | |
| PROJECT_ID="663188713804" | |
| DOCUMENT_ID="3m69velh07nj0" # 05079-86913.pdf | |
| SOURCE_FOLDER_ID="2n0md82gaqn28" # Unreviewed | |
| DESTINATION_FOLDER_ID="5hrrjcq9h3150" # Reviewed | |
| ENDPOINT="https://contentwarehouse.googleapis.com/v1/projects/$PROJECT_ID/locations/us/documents/$DOCUMENT_ID/linkedSources" | |
| REQUEST='{ | |
| "request_metadata": { | |
| "user_info": { | |
| "id": "user:drewgillson@google.com", | |
| "group_ids": [] | |
| } | |
| } | |
| }' | |
| echo $ENDPOINT | |
| # Get the current link | |
| curl -s -X POST \ | |
| -H "Authorization: Bearer $TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$REQUEST" \ | |
| $ENDPOINT > temp.json | |
| cat temp.json | jq | |
| LINK_ID=$(cat temp.json | jq -r '.documentLinks[].name' | rev | cut -d'/' -f1 | rev) | |
| # The jq command takes the JSON input and extracts the name field from | |
| # each object in the documentLinks array. rev and cut are used to extract | |
| # the last part of the string delimited by slashes (the link ID) | |
| rm temp.json | |
| ENDPOINT="https://contentwarehouse.googleapis.com/v1/projects/$PROJECT_ID/locations/us/documents/$SOURCE_FOLDER_ID/documentLinks/$LINK_ID:delete" | |
| echo $ENDPOINT | |
| # Delete the current link | |
| curl -s -X POST \ | |
| -H "Authorization: Bearer $TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$REQUEST" \ | |
| $ENDPOINT | jq | |
| ENDPOINT="https://contentwarehouse.googleapis.com/v1/projects/$PROJECT_ID/locations/us/documents/$DESTINATION_FOLDER_ID/documentLinks" | |
| REQUEST='{ | |
| "parent": "projects/'$PROJECT_ID'/locations/us/documents/'$DESTINATION_FOLDER_ID'", | |
| "document_link": { | |
| "source_document_reference": { | |
| "document_name": "projects/'$PROJECT_ID'/locations/us/documents/'$DESTINATION_FOLDER_ID'", | |
| }, | |
| "target_document_reference": { | |
| "document_name": "projects/'$PROJECT_ID'/locations/us/documents/'$DOCUMENT_ID'", | |
| }, | |
| }, | |
| "request_metadata": { | |
| "user_info": { | |
| "id": "user:drewgillson@google.com", | |
| "group_ids": [] | |
| } | |
| } | |
| }' | |
| echo $ENDPOINT | |
| # Create a new link | |
| curl -s -X POST \ | |
| -H "Authorization: Bearer $TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| -d "$REQUEST" \ | |
| $ENDPOINT | jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment