Developing a Document Approval API Client Application

Use this procedure to write a client application to work with approvables, using the Document Approval API.

Prerequisites

Your SAP Ariba procurement solution must be configured to allow external approval. Contact your SAP Ariba representative to configure your installation.

  • You can enable approval of invoices, requisitions, and/or user profiles.

  • You can also add the optional ability to track delegation/reassignment events.

Context

This topic describes what queries to make, in what order, to identify, retrieve, and act on specific approvables, providing examples for each query.

To prevent the responses to these queries from becoming too large, parameters are available to control pagination and to filter the results set. When pagination is relevant, the sample query demonstrates how to use these parameters:

$count
Controls whether number of elements in a collection is returned with the response. When this parameter is true, the count is returned inline, parallel to the value field that encloses the returned approvables data, as part of the response containing the collection itself.
$filter
Use of this parameter varies from endpoint to endpoint, always to filter the results set. Details for use of $filter are provided with the examples for each endpoint.
$skip
An offset from the beginning of the result set, used for pagination.
$top
The maximum number of records to be returned in the response. This can be used in combination with $skip for pagination purposes. For example, if $top=10 and the results set contains 100 records, the response will contain the first 10 records. To retrieve the next set of records in the results set, submit a new query with $skip=10. For the following page, $skip=20 and so on.

Procedure

  1. The client application requests a list of approvable documents by doing one of the following:
    • When an approval node is activated, the SAP Ariba procurement solution records a change in the document's state. For a list of events that cause an approval node to activate, see Events That Activate an Approval Node.

      The client application requests the list of approvables representing approvables whose state has changed, using the GET /changes endpoint.

      GET {{runtime_url}}/changes?$count={true|false}&realm={realm}&skip={offset}&top={maxRecords}&$filter=changeSequenceId gt '{ID}'

      The changed approvables will be returned in a JSON "wrapper" that includes a value block and that may include a count field. The value block lists information including the approvableID for each returned approvable. The maximum number of approvables returned will be $top or fewer. If you set $count to true, the count field will be included in the JSON response at the same level as value.

      $filter
      Restrict the set of resources that is returned to include only the changes that occurred after the last change processed by filtering the results on the changeSequenceId field. For example, $filter="changeSequenceId gt 10" would ensure that changes #1 through #10 would not be included in the response.

      Specify a time range for the GET /changes endpoint by using the $filter query parameter, such as timeCreated gt 'YYYY-MM-DDTHH:mm:ssZ' and timeCreated lt 'YYYY-MM-DDTHH:mm:ssZ', to retrieve approval changes created within the specified time range.

    • The client application requests a list of document IDs representing approvable documents that match specified filter criteria, using the GET /pendingApprovables endpoint:

      GET {{runtime_url}}/pendingApprovables?realm={realm}&$filter=approvableType eq '{requisitions|invoices}' and user eq 'user'&skip={offset}&$top={maxRecords}
                        
      passwordAdapter
      Mode of authentication.
      $filter
      Specify the desired document type by filtering on the approvableType and/or user attributes with the GET /pendingApprovables endpoint. Possible values for approvableType are invoices, requisitions, and userprofiles.
  2. The client application requests the details of one or more identified approvables, as follows:
    • To retrieve a single identified approvable by approvableID, use the GET /{approvableType}/{approvableId} endpoint.

      GET {{runtime_url}}/{requisitions|invoices|userprofiles}/{approvableId}?realm={realm}
    • To retrieve a single approvable based on the approvable's uniqueName, use the GET /{approvableType} endpoint and pass the $filter parameter.

      GET {{runtime_url}}/{requisitions|invoices|userprofiles}?realm={realm}&$count={true|false}&$filter=uniqueName eq '{uniqueName}'&$skip={offset}&$top={maxRecords}
      $filter
      In this endpoint, only uniqueName can be filtered on, and the only supported operation is eq.
    • To retrieve all approvables of the specified type, use the GET /{approvableType} endpoint and do not pass the $filter parameter.

    • GET {{runtime_url}}/{requisitions|invoices|userprofiles}?realm={realm}&$count={true|false}&$skip={offset}&$top={maxRecords}
    The response contains the details of the document or documents you requested. If the document has associated attachments, a list of attachment IDs is included in the Attachments block.
  3. Optionally, the client application can download an attachment associated with a document, using the GET /{approvableType}/{approvableId}/attachments/{attachmentId} endpoint.
    curl -o vz.pdf
    						{{runtime_url}}/{requisitions|invoices|userprofiles}/{approvableId}/attachments/{attachmentId}?realm={realm}
  4. The client application identifies users who are authorized to approve or deny the approvable. You can do this as follows:
    1. Optional. If you do not already have the ID of the group or groups authorized to act on the approvable, use the GET /groups endpoint. If you know the group's uniqueName, you can use $filter to return the specific groupId of that group. If you do not pass $filter, this endpont returns the groupId for every group.
      GET {{runtime_url}}/groups?realm={realm}&$filter=uniqueName eq '{groupName}'
    2. Retrieve the list of users with membership in the authorized group using the GET /groups/{groupId}/members endpoint.
      GET {{runtime_url}}/groups/{groupId}/members?realm={realm}
  5. The client application presents the decision to one or more authorized approvers.
  6. Either the client application or one or more approvers approve or deny the approval request, using the PATCH /{approvableType}/{ApprovableId} endoint.
    PATCH {{runtime_url}}/{requisitions|invoices|userprofiles}/{approvableId}?realm={realm}&user={userID}&passwordadapter={passwordAdapter}
    						
    		Body: 
    		{
    		"state" : "{newState}",
    		"comment" : {
    		"text": "test comment",
    		"visibleToSupplier" : "true"
    		}
    	}
    					
    state
    Optional. If you specify an approvable state in this field, the PATCH request will change the approvable's approval state to the value you specified.
    text
    Optional. If you decide to add a comment, the text of the comment goes here.
    visibleToSupplier
    If this is true, the supplier will be able to read your comment. To hide your comment from the supplier, set this false.
    showErrorDetails
    Optional. Default value is false. If true, error messages generated due to internal integration errors are included in the error block of the response, localized to the internal system's region, as part of a 500 internalServerError block, as follows:
    "error": 
    {
    	"code": "InternalServerError",
    	"message": "Internal Server Error",
    	"details": 
    		[{
    		"code": "internalCallReturnedError",
    		"message": "Localized internal call error message"
    		}]
    }