Create Web Portal Shares With Subfolders¶
You can use the API to create Web Portal shares. When outputting order data from SAP it might be required to automatically create subfolders within the share. The example below shows how to do that.
Example
#!/bin/bash
AUTH_ISSUER_URL=https://localhost:32769/auth/realms/SEAL
# get OIDC token from IDP
IDP_CFG=$(curl -k -s "$AUTH_ISSUER_URL/.well-known/openid-configuration")
#echo $IDP_CFG
TOK_END=$(echo $IDP_CFG | jq -r '.token_endpoint')
#echo $TOK_END
TOK_SET=$(curl -k -s -X POST -d "grant_type=password&client_id=seal-opcli&client_secret=ef5991b8-74a0-4d82-94d9-2221c3c83efc&username=seal-admin&password=test" $TOK_END)
#echo $TOK_SET
TOK=$(echo $TOK_SET | jq -r '.access_token')
#echo $TOK
AUTH="Authorization: Bearer $TOK"
JSON="Content-Type:application/json"
# create share
BODY='{"name":"my-share","metadata":{"description":"ruru","sharedWith":["duli@fu.de"],"expirationDate":1234567890}}'
RES=$(curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$BODY" "https://localhost:3008/v1/services/operator-webportal/repo")
DOCID=$(echo $RES | jq -r '.uuid')
SHAREHREF=$(echo $RES | jq -r '.links.self.href')
echo ""
echo "Created share with href: $SHAREHREF"
#echo "$RES"
echo "-----------------------------------------------"
# add recipient to share
BODY='{"name":"my-share","metadata":{"sharedWith":["duli@fu.de","duuuuli@fu.de"]}}'
RES=$(curl -k -s -X PATCH -H "$AUTH" -H "$JSON" -d "$BODY" "https://localhost:3008$SHAREHREF")
#echo "$RES"
echo "-----------------------------------------------"
# add collection to share
BODY='{"name":"coll-1","type":"collection"}'
RES=$(curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$BODY" "https://localhost:3008$SHAREHREF")
DOCID=$(echo $RES | jq -r '.uuid')
COLL1HREF=$(echo $RES | jq -r '.links.self.href')
echo ""
echo "Created collection with href: $COLL1HREF"
#echo "$RES"
echo "-----------------------------------------------"
# add collection to collection
BODY='{"name":"coll-2.1","type":"collection"}'
RES=$(curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$BODY" "https://localhost:3008$COLL1HREF")
DOCID=$(echo $RES | jq -r '.uuid')
COLL21HREF=$(echo $RES | jq -r '.links.self.href')
echo ""
echo "Created collection with href: $COLL21HREF"
#echo "$RES"
echo "-----------------------------------------------"
# add document to collection
BODY='{"name":"doc-2.1","type":"document"}'
RES=$(curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$BODY" "https://localhost:3008$COLL21HREF")
DOCID=$(echo $RES | jq -r '.uuid')
DOC21HREF=$(echo $RES | jq -r '.links.self.href')
echo ""
echo "Created document with href: $DOC21HREF"
#echo "$RES"
echo "-----------------------------------------------"
# add content to document
RES=$(curl -k -s -X PUT -H "$AUTH" -H "Content-Type: application/octet-stream" --data-binary "@/home/vagrant/Downloads/dina4-1.pdf" "https://localhost:3008${DOC21HREF}/content")
echo ""
echo "Content added to document"
echo "------------------------------------------------"
# add collection to collection
BODY='{"name":"coll-2.2","type":"collection"}'
RES=$(curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$BODY" "https://localhost:3008$COLL1HREF")
DOCID=$(echo $RES | jq -r '.uuid')
COLL22HREF=$(echo $RES | jq -r '.links.self.href')
echo ""
echo "Created collection with href: $COLL22HREF"
#echo "$RES"
echo "-----------------------------------------------"
# add document to collection
BODY='{"name":"doc-2.2","type":"document"}'
RES=$(curl -k -s -X POST -H "$AUTH" -H "$JSON" -d "$BODY" "https://localhost:3008$COLL22HREF")
DOCID=$(echo $RES | jq -r '.uuid')
DOC22HREF=$(echo $RES | jq -r '.links.self.href')
echo ""
echo "Created document with href: $DOC22HREF"
#echo "$RES"
echo "-----------------------------------------------"
# add content to document
RES=$(curl -k -s -X PUT -H "$AUTH" -H "Content-Type: application/octet-stream" --data-binary "@/home/vagrant/Downloads/dina4-1.pdf" "https://localhost:3008${DOC22HREF}/content")
echo ""
echo "Content added to document"
echo "------------------------------------------------"
# search documents
RES=$(curl -k -s -H "$AUTH" -H "$JSON" "https://localhost:3008/v1/services/operator-webportal/repo?metadata.description=ruru")
echo ""
echo "$RES"
echo "-----------------------------------------------"