Creating a bundle to add to the product

Login

Login as a dms user, and after login acquire the token in response.

Request

curl -H 'content-type: application/json' -X POST <dmsServer>/api/auth/login -d '{"username":"test@zentri.com", "password":"test@zentri.com"}'

Response

{"result":"ok","token":"eDZoVDZPWG1MY3N6aWZCN1M4Q0pUVFlX","client":"71e4f0f2baaa2e546aaf7e52f4147e5c"}

Then select the product that we are going to add the bundle to. Use the product’s code to get the latest firmware for the product, its platform and its flavour.

Our bundle example is built based on the sample data below:

Product

Sample data

 "product_id":"28a7c20c-774d-4d7e-9c5d-a6a67419f4e2",
 "firmware_id":"0d785d3e-94d2-4854-97ea-5eed9db270d7",

Fetch Bundle History

Fetch the bundle version history of the product and the firmware of the corresponding bundle to determine existing bundle versions. Our new bundle version must be different to existing versions.

The list of bundles is returned in a json object.

Request

curl -H 'authorization: bearer VndiOXpEblJGNnhYRGdHRTZEQmR1S2Zj' -X GET <dmsServer>/api/products/28a7c20c-774d-4d7e-9c5d-a6a67419f4e2/bundles

Response

Sample json object response

[{
    "id":"d4fe99fa-79cd-446c-81e6-77e0c5272fe4",
    "user_id":"db7d3424-3c42-4211-862f-b154cece4900",
    "firmware_id":"0d785d3e-94d2-4854-97ea-5eed9db270d7",
    "product_id":"28a7c20c-774d-4d7e-9c5d-a6a67419f4e2",
    "state":"published",
    "tag":null,
    "version":"0.9.0.11",
    "created_at":"1482283284738",
    "part_number":null,
    "description":"Testing bundle",
    "remote_id":null,
    "remote_product":null,
    "firmware":"1.0.0.4",
    "device_count":0,
    "device_count_bundle_ok":0
},{
    "id":"60b70112-9f9f-4192-b65d-7f847a025217",
    "user_id":"db7d3424-3c42-4211-862f-b154cece4900",
    "firmware_id":"0d785d3e-94d2-4854-97ea-5eed9db270d7",
    "product_id":"28a7c20c-774d-4d7e-9c5d-a6a67419f4e2",
    "state":"published",
    "tag":null,
    "version":"0.9.0.3",
    "created_at":"1482283314113",
    "part_number":null,
    "description":"Testing bundle",
    "remote_id":null,
    "remote_product":null,
    "firmware":"1.0.0.4",
    "device_count":0,
    "device_count_bundle_ok":0
}]

Create Bundle with a Unique Version Number

You can specify a version number that is different to any existing version number.

If you request a version number that already exists, the DMS responds with an error message:

Alternatively, you can leave the version number blank. The DMS returns a version number created by incrementing the highest existing version number. For example, using the sample bundle versions above, the highest version is 0.9.0.11. The DMS would return the version 0.9.0.12.

To create a new version number for your bundle, you also have to supply a firmware ID and a product ID.

Request

In this sample request, the requested version number is blank.

curl -H 'content-type: application/json' -H 'authorization: bearer VndiOXpEblJGNnhYRGdHRTZEQmR1S2Zj' -X POST <dmsServer>/api/products/28a7c20c-774d-4d7e-9c5d-a6a67419f4e2/bundles -d  '{"product_id":"28a7c20c-774d-4d7e-9c5d-a6a67419f4e2","firmware_id":"70e6442f-4d95-4095-a430-da2cf2b43974"}'

Sample json object payload, formatted more clearly:

{
    "product_id":"28a7c20c-774d-4d7e-9c5d-a6a67419f4e2",
    "firmware_id":"70e6442f-4d95-4095-a430-da2cf2b43974",
}

Response

The response is the bundle’s data in JSON format. Sample successful response:

{
    "id":"781ce63f-5859-47dc-90ea-34b04c31de45",
    "user_id":"a9fd9b6e-cf29-4761-ade2-ddfaac25a4cd",
    "firmware_id":"70e6442f-4d95-4095-a430-da2cf2b43974",
    "product_id":"28a7c20c-774d-4d7e-9c5d-a6a67419f4e2",
    "state":"preview",
    "tag":null,
    "version":"0.9.0.12",
    "created_at":"1482385819687",
    "part_number":null,
    "description":"",
    "remote_id":null,
    "remote_product":null,
    "firmware":"1.0.2.1",
    "product":"DANAIN-ADW003",
    "platform_id":"939c3dd3-bca7-4103-b961-e5e6ad339627",
    "platform":"AMW007",
    "resources":[],
    "bversion":"DANAIN-ADW003-0.9.0.12,  2016-12-22T05:50:19Z, ZentriOS-WL-1.0.2.1"
}

The bundle is created with the default state. preview. In this state, you can add resources to the bundle or remove them before it is published. Once the bundle has been published, the resources cannot be changed.

Fetch Bundle Details

Once a bundle exists, you can fetch the bundle information as follows.

curl -H 'content-type: application/json' -H 'authorization: bearer VndiOXpEblJGNnhYRGdHRTZEQmR1S2Zj' -X GET <dmsServer>/api/bundles/0d582daa-49c3-444d-95c2-97fd23c10d3f

In the response, resources are listed under the resources property. The resource id is the id property listed for each resource. For example:

...
"resources":[
{"id":"9aff7da7-5d91-4fdb-b874-4247696dd685",
...},
...
]

To add a resource

A resource is a file. The file is submitted to the DMS as a json object in the format shown below. Its contents are encoded using a base64 binary-to-text scheme. The base64 property is the file contents encoded in base64.

{"base64": "VGVzdAo=",
 "filename":"test.txt", 
 "version":"0.0.0.1", 
 "type":"MISC_FIX_LEN", 
 "mime":"text/plain"
}

The request below is used to add a resource. The response returns the id of the newly created resource.

Request

curl -H 'content-type: application/json' -H 'authorization: bearer VndiOXpEblJGNnhYRGdHRTZEQmR1S2Zj' -X POST <dmsServer>/api/bundles/0b49ba01-4c58-48f6-932e-f5024f1dd9c4/resources -d '{"base64": "VGVzdAo=", "filename":"test.txt", "version":"0.0.0.1", "type":"MISC_FIX_LEN", "mime":"text/plain"}'

Response

{"id":"eff3e4fe-009e-49a2-ac36-9eb5b0a0f03d","size":5}

To remove a resource

The request below is used to remove a resource. You supply the id of the resource. To determine bundle resource ids, you can fetch the bundle details. See Fetch Bundle Details above.

Request

curl -H 'content-type: application/json' -H 'authorization: bearer VndiOXpEblJGNnhYRGdHRTZEQmR1S2Zj' -X DELETE <dmsServer>/api/bundles/f3fef344-a362-417a-88ed-617519eb364f/resources/a0f0db09-1baa-4e79-8817-3809c039d2a8

Response

`200 OK`

Trash Bundle

If at any point you wish to remove the existing bundle, you can set the bundle’s state to trash. The system will then delete the bundle.

Request

curl -H 'content-type: application/json' -H 'authorization: bearer VndiOXpEblJGNnhYRGdHRTZEQmR1S2Zj' -X POST <dmsServer>/api/bundles/f3fef344-a362-417a-88ed-617519eb364f/state -d '{"state": "trash"}'

Sample json object Payload

{"state": "trash"}

Response

{"result":"ok"}

Set Bundle State

Once the file has been uploaded, you can change the bundle state.

Request

curl -H 'content-type: application/json' -H 'authorization: bearer VndiOXpEblJGNnhYRGdHRTZEQmR1S2Zj' -X POST http://localhost:2002/api/bundles/f3fef344-a362-417a-88ed-617519eb364f/state -d '{"state": "published"}'

The possible states are preview, trash, published, archive.

Newly created bundles default to preview.

A bundle state preview can be changed to state published or trash.

A bundle in state archive can be changed to state published or trash.

A bundle in published state can be changed to state archive.

Once the bundle is set to trash it is deleted from the system.

Sample json object payload:

{"state": "trash"}

Respond

{"result":"ok"}

Set Bundle Tag

You can set the tag after it published.

Request

curl -H 'content-type: application/json' -H 'authorization: blJGNnhYRGdHRTZEQmR1S2Zj' -X POST <dmsServer>/api/bundles/781ce63f-5859-47dc-90ea-34b04c31de45/tag -d '{"tag": ""}'

A tag is one of alpha, beta, release or "" (nothing) The default is nothing.

Sample json object payload:

{"tag": "beta"}

Response

{"result":"ok"}