USER=admin
PASSWORD=admin123!
URL=http://localhost:8080

# Step 1. Create provider organization
ORG=provider
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"name\":\"$ORG\",\"description\":\"\"}" $URL/apiman/organizations/

# create a plan
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"name\":\"plan\", \"description\":\"\", \"initialVersion\":\"1.0\"}" $URL/apiman/organizations/$ORG/plans/

# lock plan
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"type\":\"lockPlan\",\"entityId\":\"plan\",\"entityVersion\":\"1.0\",\"organizationId\":\"$ORG\"}" $URL/apiman/actions/

# create API
API=api
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"name\":\"$API\", \"description\":\"\", \"definitionUrl\":\"http://some_host\", \"endpointContentType\":\"json\", \"definitionType\":\"None\", \"initialVersion\":\"1.0\", \"endpoint\":\"http://some_host\", \"publicAPI\":\"true\", \"plans\":[ { \"version\":\"1.0\", \"planId\":\"plan\" }], \"endpointType\":\"rest\", \"parsePayload\":\"false\"}" $URL/apiman/organizations/$ORG/apis/

# publish API
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"type\":\"publishAPI\",\"entityId\":\"$API\",\"entityVersion\":\"1.0\",\"organizationId\":\"$ORG\"}" $URL/apiman/actions/

# Step2. Create client organization #1 and sign a contract
CLIENT_ORG_1=clientA
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"name\":\"$CLIENT_ORG_1\",\"description\":\"\"}" $URL/apiman/organizations/

# create new client application for user within organization
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"name\":\"ClientApp\",\"description\":\"\",\"initialVersion\":\"1.0\"}" $URL/apiman/organizations/$CLIENT_ORG_1/clients/

# create new contract within client application (json)
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"planId\":\"plan\",\"apiOrgId\":\"$ORG\",\"apiId\":\"$API\",\"apiVersion\":\"1.0\"}" $URL/apiman/organizations/$CLIENT_ORG_1/clients/ClientApp/versions/1.0/contracts/

# Step 3. Create client organization #2 and sign a contract
CLIENT_ORG_2=clientB
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"name\":\"$CLIENT_ORG_2\",\"description\":\"\"}" $URL/apiman/organizations/

# create new client application for user within organization
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"name\":\"ClientApp\",\"description\":\"\",\"initialVersion\":\"1.0\"}" $URL/apiman/organizations/$CLIENT_ORG_2/clients/

# create new contract within client application (json)
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"planId\":\"plan\",\"apiOrgId\":\"$ORG\",\"apiId\":\"$API\",\"apiVersion\":\"1.0\"}" $URL/apiman/organizations/$CLIENT_ORG_2/clients/ClientApp/versions/1.0/contracts/

# register contract of client organization #1
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"type\":\"registerClient\",\"entityId\":\"ClientApp\",\"entityVersion\":\"1.0\",\"organizationId\":\"$CLIENT_ORG_1\"}" $URL/apiman/actions/

# register contract of client organization #2
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"type\":\"registerClient\",\"entityId\":\"ClientApp\",\"entityVersion\":\"1.0\",\"organizationId\":\"$CLIENT_ORG_2\"}" $URL/apiman/actions/

# unregister contract of client organization #1
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"type\":\"unregisterClient\",\"entityId\":\"ClientApp\",\"entityVersion\":\"1.0\",\"organizationId\":\"$CLIENT_ORG_1\"}" $URL/apiman/actions/

# unregister contract of client organization #2
curl --user $USER:$PASSWORD -X POST -H "Content-Type: application/json" -d "{\"type\":\"unregisterClient\",\"entityId\":\"ClientApp\",\"entityVersion\":\"1.0\",\"organizationId\":\"$CLIENT_ORG_2\"}" $URL/apiman/actions/

