Search code examples
oracle-databaserestcloud

Exporting and Importing Applications From VBCS With REST Calls


Ref - https://support.oracle.com/cloud/faces/DocumentDisplay?id=2637471.1&_adf.ctrl-state=h87zqwsi3_730&_afrLoop=213040896345615

Can anybody help with a sample payload to invoke 'Import Applications' POST method to programmatically import the application to the Oracle Visual Builder Cloud Service.

I know I don't have the Content-Type or the request body or both not correct. I'm using Postman to test the endpoint

Steps

  1. Setup the Oracle Visual Builder Cloud Service instance in https://cloud.oracle.com/?region=
  2. Created an 'Visual Builder' instance in oracle cloud for my login/ tenancy
  3. Launched the VBCS home page and created one or more applications
  4. Used the VBCS REST endpoint (GET /resources/application/exportresources/{projectid}-{version}) to export one of the applications
  5. I'm trying to import the application (POST /resources/application/importresources) to another VBCS instance but unable to determine the correct 'Content-Type' or the request payload format. I keep getting HTTP 415 or 400 error

Code shown below. SERVICENAME-CLOUDACCOUNT.SERVICETYPE is replaced from oracle cloud account.

curl --location --request POST 'https://SERVICENAME-CLOUDACCOUNT.SERVICETYPE.ocp.oraclecloud.com/ic/builder/resources/application/importresources' \ 
--header 'Authorization: Bearer yourOAuthToken' \ 
--header 'Content-Type: application/vnd.oracle.adf.error+json;application/json;application/vnd.oracle.adf.resourceitem+json;application/vnd.oracle.adf.resourcecollection+json' \
--header 'REST-Framework-Version: 4' \
--data-raw '{
"branchId": "0",
"importMode": "xyz",
"name": "Test",
"description": "sample",
"location": null,
"fileName": "abc",
"unzip": null
}'

Solution

  • I debugged the visual builder cloud instance logs to find the details of the rest api call. When importing the application from the front end ( OVBCS development platform UI ), the logic utilizes the 'Import Applications' endpoint.

    Here is the working curl script for importing application resources to the oracle visual builder cloud instance using the REST end points

    1. Login to Oracle Cloud using your cloud account credentials and tenancy

    2. On navigation menu on top left -> OCI Classic Services -> Platform Services -> Visual Builder

    3. Create an instance if you don't have one already. Click on the active instance and Start it up

    4. Grab your VBCS instance base url. It will be something like https://yourInstanceName-yourTenancy.builder.ocp.oraclecloud.com/ic/builder/

    5. Assuming you have a visual application created in your VBCS instance. Ref here

    6. Assuming you are familiar with generating bearer token for oracle cloud applications. The OAuthToken mentioned in the below samples are generated based on your preferred OAuthType ( ResourceOwner or JWT or whatever setup you have for your cloud application)

    7. Export your application. response will be zip file contents. save it to your file system

      curl --location --request GET 'https://yourInstanceName-yourTenancy.builder.ocp.oraclecloud.com/ic/builder/resources/application/exportresources/yourAppId-yourAppVersion' --header 'Authorization: Bearer OAuthToken'

    8. Let's say you saved the exported file in C:\temp\yourAppId-yourAppVersion.zip

    9. Import your application as new application in the target instance

      curl --location --request POST 'https://yourInstanceName-yourTenancy.builder.ocp.oraclecloud.com/ic/builder/resources/application/importresources?branchId=yourAppId&importMode=CREATE_NEW_APP&name=yourAppName&description=SomeOptionalDesc&fileName=yourAppId-yourAppVersion.zip&unzip=true' --header 'Authorization: Bearer OAuthToken' --header 'Content-Type: application/zip' --data-binary '@/C:/temp/yourAppId-yourAppVersion.zip'

    10. Import your application to an existing application in the target instance. It will override the existing application version with the contents that you are importing.

      curl --location --request POST 'https://yourInstanceName-yourTenancy.builder.ocp.oraclecloud.com/ic/builder/resources/application/importresources?branchId=yourAppId-yourAppVersion&importMode=KEEP_EXISTING&name=YourAppName&description=SomeOptionalDesc&fileName=yourAppId-yourAppVersion.zip&unzip=true' --header 'Authorization: Bearer OAuthToken' --header 'Content-Type: application/zip' --data-binary '@/C:/temp/yourAppId-yourAppVersion.zip'