Optimise a ServiceAPI post with FindBy

The most obvious way to specify a RecordType, Container, Location or other object property is using its Uri, for example you might post this to create a new Record:

{
    "RecordTitle": "My Title",
    "RecordRecordType": {"Uri": 1}
}

FindBy

If you know the Uri then all is good, if not you will have to make a separate request to find the Uri.  If you do not know the Uri but do have some other unique information about the object, such as its name, or relationship to you (e.g. supervisorOf:Me) then you may use the FindBy, for example:

{
    "RecordTitle": "My Title",
    "RecordRecordType": {"FindBy":"name:Document"}
}

This method may be used with a standard and multipart form post as well, simply post the string rather than the Uri, for example:

------WebKitFormBoundary8Pd5W3BlMsyEl0k8
Content-Disposition: form-data; name="RecordRecordType"

name:Document
------WebKitFormBoundary8Pd5W3BlMsyEl0k8
Content-Disposition: form-data; name="RecordTitle"

My Title
------WebKitFormBoundary8Pd5W3BlMsyEl0k8--

Beware

The FindBy is a standard search string so you can use any search you want, the only limitation is that it must match one and only one object, if zero, or more than one matches are found the entire request will fail.

Demonstration

The following video demonstrates this via Postman.

Written on October 6, 2016