↓ Skip to main content
A pen and ink drawing of a post office sorting desk. In the middle lies a thick stack of teal envelopes tied together with one orange ribbon and a bow. Behind it stand a brass letter scale and pigeonholes full of teal envelopes, and a wooden tray holds a few loose ones. In front lie a spool of orange ribbon and a pair of scissors, with a rubber stamp at the side.

Bulk Requests and allornothing in the Maximo REST API

The Maximo REST API in Practice - This article is part of a series.
Part 8: This Article
One request can create, update and delete many records. Manage then answers with one entry per record, and the HTTP status of the whole request says almost nothing. This article shows how Manage reads each item, what the allornothing header changes, and how to delete a record.

The rules here come from IBM’s documentation and from our own work with the REST API, on Manage in the MAS 9.2 series. We ran every request on our test system, against IBM’s demo data, as a user without administrator rights. The examples write service requests through the object structure MXAPISR, because a normal user may create and delete them. Assets and work orders refuse a delete, more on that at the end.

One request, many records
#

A bulk request is a POST to the collection URI with the header x-method-override: BULK. The body is a JSON array, and each element is one item. Manage looks at two things in each item: the href and the _action.

What Manage does with one item of a bulk request What Manage does with one item of a bulk request
What Manage does with one item of a bulk request

So _action alone never decides. An item without href and with _action: Update creates a record, and we show that trap below.

A first bulk request
#

Two new service requests in one call:

POST /maximo/api/os/mxapisr?lean=1
x-method-override: BULK
[
  {
    "description": "Air conditioning too loud",
    "siteid": "BEDFORD",
    "_action": "Add"
  },
  {
    "description": "Door to store room sticks",
    "siteid": "BEDFORD"
  }
]

Manage answers 200. The body has one entry per item, in the order of the request:

[
  {
    "_responsemeta": {
      "status": "201",
      "Location": "http://…/maximo/api/os/mxapisr/_U1IvMTE5NA--"
    }
  },
  {
    "_responsemeta": {
      "status": "201",
      "Location": "http://…/maximo/api/os/mxapisr/_U1IvMTE5NQ--"
    }
  }
]

Three details matter for a client:

  • status is a string. Compare it with "201", or convert it first. Our first test script compared it with a number and missed every created record.
  • Location is an absolute URI. Its host comes from the server setting for the public URI of the API, so it can differ from the host you called. Cut it at /api/os/ when you call it again.
  • The second item has no _action and creates a record too. Add is the default.

What each item does
#

The same request can mix all kinds of items. Here the first item updates the first request, the second deletes the other one, and the third creates a new one:

[
  {
    "href": "/maximo/api/os/mxapisr/_U1IvMTE5NA--",
    "description": "Air conditioning too loud, room 2",
    "_action": "Update"
  },
  {
    "href": "/maximo/api/os/mxapisr/_U1IvMTE5NQ--",
    "_action": "Delete"
  },
  {
    "description": "Light in the hall is out",
    "siteid": "BEDFORD"
  }
]

The answer holds "status": "204" for the update and the delete, and 201 with a Location for the create. The table lists every item form we tested:

ItemWhat Manage doesItem status
no href, no _action or Addcreates a record201
href, any _action but Deleteupdates the record204
href and _action: Deletedeletes the record204
keys and _action: Changeupdates the record with these keys204
keys and _action: Deletedeletes the record with these keys204
keys and _action: AddChangeupdates, or creates when no record has the keys204 or 201

For a service request the keys are ticketid and class. An item with only ticketid fails with BMXAA1496E, “The SR record does not exist”, because Manage needs every key.

An update item takes the attributes of a single update, which the previous article covers.

Two traps from the examples
#

IBM’s examples contain two items that look right and do something else. We ran both:

  • _action: Update without href. IBM’s mixed example updates an asset with only a description and _action: Update. Manage creates a new record with that description. Without href or keys, nothing points at an existing record.
  • _Action with a capital A. The delete item of the same example writes "_Action": "Delete". JSON keys are case sensitive, so Manage sees no _action. The item has an href, so it becomes an update. The answer is 204, and the record is still there.

Write _action in lower case, and give every update or delete an href or the full key.

When an item fails
#

Without further headers, each item runs in its own transaction. A failing item is rolled back, and the next item runs as if nothing happened. The request still answers 200:

[
  {
    "_responsedata": {
      "Error": {
        "errorattrname": "siteid",
        "errattrvalue": "NOSITE",
        "reasonCode": "BMXAA3906E",
        "message": "BMXAA3906E - Site NOSITE is not valid.",
        "statusCode": "400"
      }
    },
    "_responsemeta": { "status": "400" }
  },
  {
    "_responsemeta": {
      "status": "201",
      "Location": "http://…/maximo/api/os/mxapisr/_U1IvMTE5OA--"
    }
  }
]

We shortened the error object. It also carries errorobjpath, extendedError and a timestamp, the same object as for a single request. So a client must read every entry: a 200 on the request only says that the JSON was readable.

One case breaks even that rule. An element that is not a JSON object, a string or a number in the array, fails the whole request with 500 and a Java class cast message. The items before it were saved anyway, each time we tried it.

stoponerror: stop at the first failure
#

With the header stoponerror: 1, Manage stops at the first failing item. The items before it stay saved, and the items after it are skipped. The answer then has fewer entries than the request had items: for three items with a bad second one, the answer holds two entries.

allornothing: one transaction for all items
#

The header allornothing: 1 puts every item into one transaction. Manage commits after the last item. When an item fails, Manage rolls back the items before it and does not run the items after it. The answer is no longer an array. It is the error of the failing item, with that item’s HTTP status:

POST /maximo/api/os/mxapisr?lean=1
x-method-override: BULK
allornothing: 1
{
  "Error": {
    "errorattrname": "siteid",
    "reasonCode": "BMXAA3906E",
    "message": "BMXAA3906E - Site NOSITE is not valid.",
    "statusCode": "400"
  }
}

The request answers 400. We looked for each record afterwards: none of the three items was saved, the good item in front of the bad one included. When every item passes, the answer is the normal array with 201 and 204 entries.

Two details we measured:

  • The value must be exactly 1. With allornothing: true, Manage ignores the header. The good item was saved and the bad one failed, as without the header.
  • A delete by href is never saved in this mode. The item answers 204, and the record is still there afterwards. This held when the delete was the only item and when it came after a create; the create was saved. If a batch must delete records, send the deletes in a request without allornothing.

_bulkid: match the answer to the item
#

An item can carry _bulkid with any value. Manage echoes it in _responsemeta:

{
  "_responsemeta": {
    "_bulkid": "row-17",
    "status": "201",
    "Location": "http://…/maximo/api/os/mxapisr/_U1IvMTIwNw--"
  }
}

The order of the answer already matches the request, so _bulkid matters most with stoponerror, where entries are missing, and when a client reads the answer later.

The _meta form
#

An item can also split its instructions from its data. _meta says what to do, and _data holds the attributes:

[
  {
    "_meta": {
      "method": "PATCH",
      "uri": "/maximo/api/os/mxapisr/_U1IvMTIxOA--",
      "properties": "description",
      "_bulkid": "m1"
    },
    "_data": { "description": "Door to store room sticks" }
  },
  {
    "_meta": {
      "method": "DELETE",
      "uri": "/maximo/api/os/mxapisr/_U1IvMTIxOQ--"
    }
  },
  {
    "_meta": { "method": "POST" },
    "_data": { "description": "Window cracked", "siteid": "BEDFORD" }
  }
]

method takes POST, PATCH, DELETE and SYNC. Every other entry in _meta acts as a request header for that item. Here properties makes the PATCH answer 200 with the description in _responsedata. A properties header on the whole request does the same for every create and update item.

A bulk action
#

A bulk request also works with an action on the URI. Each item names a record with its href, and the rest of the item is the body of the action:

POST /maximo/api/os/mxapisr?lean=1&action=wsmethod:changeStatus
x-method-override: BULK
[
  {
    "href": "/maximo/api/os/mxapisr/_U1IvMTIyMQ--",
    "status": "QUEUED"
  },
  {
    "href": "/maximo/api/os/mxapisr/_U1IvMTIyMg--",
    "status": "NOSUCH"
  }
]

The first item answered 204, and its record went to QUEUED. The second answered 400 with BMXAA4295E, because NOSUCH is no value of the status domain. A later article in this series covers actions in full.

SYNC: create or update by key
#

SYNC is the single-record cousin of the key items. It is a POST to the collection URI with x-method-override: SYNC. Manage looks for a record with the keys in the body:

POST /maximo/api/os/mxapisr?lean=1
x-method-override: SYNC
{
  "ticketid": "SR-2041",
  "class": "SR",
  "siteid": "BEDFORD",
  "description": "Water on the floor in room 4"
}

When a record has these keys, Manage updates it and answers 204. When none has them, Manage creates the record and answers 201 with a Location. So a client that sends the same data twice gets one record, which suits an interface that resends.

IBM’s example adds patchtype: MERGE. With it, a SYNC for a key that does not exist fails with BMXAA1496E, “The SR record does not exist”. Add "_action": "AddChange" to the body, and the merge creates the record again. That create answered 201 without a Location header, so a client has to build the URI from the keys. In a bulk request, SYNC is an item with "_meta": {"method": "SYNC"}.

Deleting a record
#

There are three ways to delete one record, and one way that looks like a delete and is none:

RequestAnswerResult
HTTP DELETE on the record URI204deleted
POST with x-method-override: DELETE204deleted
PATCH with patchtype: MERGE and {"_action": "Delete"}200deleted
PATCH with {"_action": "Delete"}204not deleted

IBM’s page on deleting resources shows the last line as the POST form of a delete. A plain PATCH ignores _action at the top level, so the record stays, and the 204 looks like success. Use the override.

A second DELETE on the same URI answers 404 with BMXAA8727E. That makes a delete safe to retry.

Can this record be deleted?
#

The action system:candelete asks before you try:

GET /maximo/api/os/mxapisr/<rest id>?lean=1&action=system:candelete

When the delete is allowed, Manage answers 200 with the record itself. When it is refused, the answer is the error a delete would give. On a collection URI the action fails with BMXAA10144E, “Missing Mbo reference”, because it needs one record. Its sibling system:canadd works on the collection and answers {"canadd": 1}.

The REST API only calls the delete of the business object, and the object decides. We met three refusals on our test system:

  • A service request with a work log entry fails with CTGRD0053E, “This ticket cannot be deleted because there are work log entries associated with it”.
  • An asset fails with BMXAA0024E, “The action DELETE is not allowed on object ASSET”. This held for an administrator too.
  • A work order fails with the same message for the object WORKORDER, through MXAPIWODETAIL. Through MXAPIWO, a new work order in status WAPPR was deleted. The structure decides, as the article on object structures shows.

Many objects with a status work this way. From the moment a work order is created, related tables already hold rows for it, its status history for one. So Manage keeps the record, and a status change ends its life. A work order is cancelled:

POST /maximo/api/os/mxapiwodetail/<rest id>
     ?action=wsmethod:changeStatus
x-method-override: PATCH
{ "status": "CAN", "memo": "Created by mistake" }

The request answered 204, and the work order went to the status CAN. A delete of the cancelled work order still failed with BMXAA0024E. Assets leave service the same way, with a status change.

Errors at a glance
#

RequestAnswerFix
a bulk POST to a record URI400 BMXAA10175Euse the collection URI
an element that is not an object500, earlier items savedsend only objects
an item with an invalid value200, item 400read every entry
allornothing: 1 and a bad item400, nothing savedfix the item, send all again
_action: Change without the full keyitem 400 BMXAA1496Eadd every key, such as class
SYNC with MERGE, key unknown400 BMXAA1496Eadd "_action": "AddChange"
a delete inside allornothing: 1item 204, record staysdelete without the header
PATCH with _action: Delete204, record staysuse x-method-override: DELETE
DELETE on a deleted record404 BMXAA8727Enothing to do
system:candelete on a collection400 BMXAA10144Ecall it on one record
delete a ticket with a work log400 CTGRD0053Ekeep the record
delete an asset or a work order400 BMXAA0024Ecancel it with a status change

Examples
#

Each request below ran on our test system.

Create two records and get them back:

POST /maximo/api/os/mxapisr?lean=1
x-method-override: BULK
properties: ticketid,status,description
[
  { "description": "Air conditioning too loud", "siteid": "BEDFORD" },
  { "description": "Door to store room sticks", "siteid": "BEDFORD" }
]

Each entry carries the record in _responsedata, so the client learns the new ticket numbers without a second call.

Change two records by their keys:

[
  {
    "ticketid": "1216",
    "class": "SR",
    "description": "Air conditioning too loud, room 2",
    "_action": "Change"
  },
  {
    "ticketid": "1217",
    "class": "SR",
    "_action": "Delete"
  }
]

Create all or nothing:

POST /maximo/api/os/mxapisr?lean=1
x-method-override: BULK
allornothing: 1
[
  { "description": "Window cracked", "siteid": "BEDFORD" },
  { "description": "Window jammed", "siteid": "BEDFORD" }
]

Delete one record:

POST /maximo/api/os/mxapisr/<rest id>
x-method-override: DELETE

What comes next
#

IBM’s own pages are the reference to keep next to this article:

The next article attaches files to records: upload, download, thumbnails and the metadata of an attachment. The series overview lists all parts. If you want help with the REST API in your own Manage, our services page shows how we work, or get in touch.

IBM and Maximo are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide.

The Maximo REST API in Practice - This article is part of a series.
Part 8: This Article