Import Items
Definition¶
POST /apis/v2/{SERVICE_ID}/{ITEMS_NAME}/import
Description¶
Add a list of items from a .b2b
file.
Details:
- The user can choose to override the existing data or not.
- If there is an error with the import of an item, the other items will still be imported.
Permissions¶
The user needs to have the permissions:
SERVICE_ID=read && SERVICE_ID=edit
To import an item, the user needs to have the associated Application Publisher Profile.
Parameters¶
The body request parameter is a JSON object which consists of the imported data and the overwritten boolean.
Field’s name | Type | Mandatory | Description |
---|---|---|---|
data | string | yes | The imported items |
overwritten | boolean | default: false | Whether the existing data is overwritten by the imported items |
The imported items must validate the service’s items rules.
Example:
{ "data" : "[{\"appKey\":\"\",\"contentMode\":\"READ\",\"description\":{\"EN\":\"Invoice analysis - Failed invoice amount and count per month (bar and line charts, rolling 12 month)\"},\"lastModifiedBy\":\"roxane.mace@amalto.com\",\"lastModifiedDate\":1520585872348,\"name\":\"Failed invoice amount and count per month\",\"revisionId\":\"fe1915748822b9fbf3da6f344e3a0d9f\",\"scriptId\":\"Reporting_Generate_Period_DataSources (reports_auto_upgrade)\",\"template\":\"var myQuery = 'select * order by creationdate'\\r\\n\\r\\n\\r\\n var query = new google.visualization.Query('${proxyrooturl}&access_token=${accesstoken}&table=ds_invoices_failed_period');\\r\\n\\r\\n \\r\\n\\r\\n\\r\\n\/\/ Apply query language statement.\\r\\nquery.setQuery(myQuery);\\r\\n\\r\\n\/\/ Send the query with a callback function.\\r\\nquery.send(handleQueryResponse);\\r\\n\\r\\nvar chart = null;\\r\\n\\r\\nfunction handleQueryResponse(response) {\\r\\n \\r\\n if (response.isError()) {\\r\\n alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());\\r\\n return;\\r\\n }\\r\\n\\r\\n var data = response.getDataTable();\\r\\n\\r\\n var nbColumns = data.getNumberOfColumns();\\r\\n\\r\\n var columnIndex = data.getColumnIndex(\\\"pendingcount\\\");\\r\\n if (columnIndex != -1) {\\r\\n data.setColumnLabel(columnIndex, \\\"Pending\\\")\\r\\n }\\r\\n\\r\\n columnIndex = data.getColumnIndex(\\\"rejectedcount\\\");\\r\\n if (columnIndex != -1) { \\r\\n data.setColumnLabel(columnIndex, \\\"Rejected\\\")\\r\\n }\\r\\n\\r\\n columnIndex = data.getColumnIndex(\\\"invalidcount\\\");\\r\\n if (columnIndex != -1) {\\r\\n data.setColumnLabel(columnIndex, \\\"Invalid\\\")\\r\\n }\\r\\n\\r\\n columnIndex = data.getColumnIndex(\\\"invoiceamount\\\");\\r\\n if (columnIndex != -1) {\\r\\n data.setColumnLabel(columnIndex, \\\"Total amount\\\")\\r\\n }\\r\\n\\r\\n var formatter = new google.visualization.NumberFormat({\\r\\n groupingSymbol: ',',\\r\\n fractionDigits: 0\\r\\n });\\r\\n\\r\\n for(var pas = 1; pas < nbColumns - 1; pas++) {\\r\\n formatter.format(data, pas);\\r\\n }\\r\\n\\r\\n chart = new google.visualization.ChartWrapper({\\r\\n \\\"chartName\\\": \\\"Chart 1\\\",\\r\\n \\\"chartType\\\": \\\"ComboChart\\\",\\r\\n \\\"containerId\\\": \\\"#chartdivid#\\\",\\r\\n \\\"dataTable\\\": data,\\r\\n \\\"isDefaultVisualization\\\": false,\\r\\n \\\"options\\\": {\\r\\n \\\"title\\\": \\\"Failed invoices - Invoice amount and count per month\\\",\\r\\n \\\"titleTextStyle\\\": {\\r\\n \\\"bold\\\": true,\\r\\n \\\"color\\\": \\\"#000\\\",\\r\\n \\\"fontSize\\\": 16,\\r\\n \\\"fontName\\\": \\\"Tahoma\\\"\\r\\n },\\r\\n \\\"booleanRole\\\": \\\"certainty\\\",\\r\\n \\\"series\\\": {\\r\\n 0: {\\r\\n \\\"type\\\": \\\"bars\\\",\\r\\n \\\"targetAxisIndex\\\": 0\\r\\n },\\r\\n 1: {\\r\\n \\\"type\\\": \\\"bars\\\",\\r\\n \\\"targetAxisIndex\\\": 0\\r\\n },\\r\\n 2: {\\r\\n \\\"type\\\": \\\"bars\\\",\\r\\n \\\"targetAxisIndex\\\": 0\\r\\n },\\r\\n 3: {\\r\\n \\\"type\\\": \\\"line\\\",\\r\\n \\\"targetAxisIndex\\\": 1\\r\\n }\\r\\n },\\r\\n \\\"animation\\\": {\\r\\n \\\"duration\\\": 500\\r\\n },\\r\\n \\\"legend\\\": \\\"in\\\",\\r\\n \\\"vAxes\\\": { \\r\\n 1: {\\r\\n \\\"title\\\": \\\"Invoice amount (USD)\\\",\\r\\n \\\"minValue\\\": 0,\\r\\n \\\"viewWindowMode\\\": 'explicit',\\r\\n \\\"viewWindow\\\": {\\r\\n \\\"max\\\": null,\\r\\n \\\"min\\\": null\\r\\n }\\r\\n },\\r\\n 0: {\\r\\n \\\"title\\\": \\\"Invoice count\\\",\\r\\n \\\"minValue\\\": 0,\\r\\n \\\"useFormatFromData\\\": true\\r\\n }\\r\\n },\\r\\n \\\"hAxis\\\": {\\r\\n \\\"useFormatFromData\\\": true,\\r\\n \\\"slantedText\\\": false\\r\\n }\\r\\n }\\r\\n });\\r\\n\\r\\n chart.draw();\\r\\n\\r\\n}\\r\\n\\r\\n\\r\\nwindow.onresize = function () {\\r\\n if (chart!=null)\\r\\n chart.draw();\\r\\n};\\r\\n\"}]", "overwrite": true }
Response¶
HTTP code | Reason |
---|---|
200 | Success |
400 | Invalid parameter count or content |
403 | Unauthorized |
409 | Conflict |
500 | Unexpected exception |
When the query is successful, the HTTP response is a 200 OK and returns the multi-error object with no message and no errors:
{ "processed" : 1, "errors" : {}, "message" : "" }
If the request parameter is null, the HTTP response is a 400 Invalid parameter:
{ "status": 400, "code": 400, "message": "Unexpected error importing the items!", "link": null, "developerMessage": "Invalid parameter count or content: the import parameters cannot be null.", "conflictInformation": null }
If the user does not have the right permissions, it will return a non-empty multi-error object with the HTTP Response 403 Unauthorized:
{ "processed": 1, "errors": { "Failed invoice amount and count per month": { "cause": null, "stackTrace": [ { "methodName": "checkEditPermission", "fileName": "AbstractServiceResource.java", "lineNumber": 704, "className": "com.amalto.b2box.core.impl.servicecomponent.resources.AbstractServiceResource", "nativeMethod": false }, { "methodName": "checkPermissions", "fileName": "AbstractServiceResource.java", "lineNumber": 721, "className": "com.amalto.b2box.core.impl.servicecomponent.resources.AbstractServiceResource", "nativeMethod": false } ], "status": 403, "code": 403, "link": null, "developerMessage": "Unauthorized: permission 'edit' is missing.", "conflictInformation": null, "message": "Unexpected error importing the items! You need to have the permission 'edit'.", "localizedMessage": "Unexpected error importing the items! You need to have the permission 'edit'.", "suppressed": [] } }, "message": "Unexpected error importing the items!" }
If the user wants to overwrite an item which has been updated since it has been exported, it will return a non-empty multi-error object with the HTTP Response 409 Conflict:
{ "processed" : 1, "errors" : { "Failed invoice amount and count per month" : { "cause" : null, "stackTrace" : [ { "methodName" : "upsertItem", "fileName" : "DAOServiceConfigurationManager.java", "lineNumber" : 110, "className" : "com.amalto.b2box.core.impl.servicecomponent.configuration.DAOServiceConfigurationManager", "nativeMethod" : false }, { "methodName" : "upsertItem", "fileName" : "ScriptsConfigurationManager.java", "lineNumber" : 27, "className" : "com.amalto.service.scripts.ScriptsConfigurationManager", "nativeMethod" : false }, { "methodName" : "handle", "fileName" : "StatisticsHandler.java", "lineNumber" : 169, "className" : "org.eclipse.jetty.server.handler.StatisticsHandler", "nativeMethod" : false }, { "methodName" : "handle", "fileName" : "HandlerWrapper.java", "lineNumber" : 134, "className" : "org.eclipse.jetty.server.handler.HandlerWrapper", "nativeMethod" : false }, { "methodName" : "handle", "fileName" : "RewriteHandler.java", "lineNumber" : 335, "className" : "org.eclipse.jetty.rewrite.handler.RewriteHandler", "nativeMethod" : false }, { "methodName" : "run", "fileName" : "HttpChannel.java", "lineNumber" : 267, "className" : "org.eclipse.jetty.server.HttpChannel", "nativeMethod" : false }, { "methodName" : "run", "fileName" : "Thread.java", "lineNumber" : 748, "className" : "java.lang.Thread", "nativeMethod" : false } ], "status" : 409, "code" : -1, "link" : null, "developerMessage" : null, "conflictInformation" : [{ "itemId" : "Failed invoice amount and count per month", "lastAuthor" : "roxane.mace@amalto.com", "lastModificationDate" : 1520599965330 }], "message" : "Conflict on saving the item 'Failed invoice amount and count per month'. This item has been modified by roxane.mace@amalto.com at Fri Mar 09 12:52:45 GMT 2018 since this item was read.", "localizedMessage" : "Conflict on saving the item 'Failed invoice amount and count per month'. This item has been modified by roxane.mace@amalto.com at Fri Mar 09 12:52:45 GMT 2018 since this item was read.", "suppressed" : [] } }, "message" : "Unexpected error importing the items!" }