Client

sapimclient.client

Asynchronous Client to interact with SAP Incentive Management REST API.

Hint

See Examples

Asynchronous Client to interact with SAP Incentive Management REST API.

class sapimclient.Tenant[source]

Bases: object

Asynchronous interface to interacting with SAP Incentive Management REST API.

Parameters:
  • tenant (str) – Your tenant ID. For example, if the login url is https://cald-prd.callidusondemand.com/SalesPortal/#!/, the tenant ID is cald-prd.

  • session (ClientSession) – An aiohttp ClientSession.

  • verify_ssl (bool, optional) – Enable SSL verification. Defaults to True.

  • request_timeout (int, optional) – Request timeout in seconds. Defaults to 60.

property host: str

The fully qualified hostname.

async _request(method: HTTPMethod, uri: str, params: dict | None = None, json: list | None = None) dict[str, Any][source]

Send a request.

Parameters:
  • method (str) – HTTP method (GET, POST, PUT, DELETE, UDPATE).

  • uri (str) – API endpoint URI.

  • params (dict, optional) – Query parameters.

  • json (list, optional) – JSON payload.

Returns:

The JSON response.

Return type:

dict

Raises:
  • SAPConnectionError – If the connection fails.

  • SAPNotModifiedError – If the resource has not been modified.

  • SAPResponseError – If the response status is not as expected.

  • SAPBadRequestError – If the request status indicates an error.

async create(resource: T) T[source]

Create a new resource.

Parameters:

resource (T) – The resource to create.

Returns:

The created resource.

Return type:

T

Raises:
  • SAPAlreadyExistsError – If the resource already exists.

  • SAPMissingFieldError – If one or more required fields are missing.

  • SAPResponseError – If the creation encountered an error.

async update(resource: T) T[source]

Update an existing resource.

Parameters:

resource (T) – The resource to update.

Returns:

The updated resource.

Return type:

T

Raises:

SAPResponseError – If the update encountered an error.

async delete(resource: T) bool[source]

Delete a resource.

Parameters:

resource (T) – The resource to delete.

Returns:

True if the resource was deleted. Raises an exception othwise.

Return type:

bool

Raises:
  • SAPDeleteFailedError – If the deletion failed.

  • SAPResponseError – If the deletion encountered an error.

async read_all(resource_cls: type[T], *, filters: BooleanOperator | LogicalOperator | str | None = None, order_by: list[str] | None = None, page_size: int = 10) AsyncGenerator[T, None][source]

Read all matching resources.

Parameters:
  • resource_cls (type[T]) – The type of the resource to list.

  • filters (BooleanOperator | LogicalOperator | str, optional) – The filters to apply.

  • order_by (list[str], optional) – The fields to order by.

  • page_size (int, optional) – The number of resources per page. Defaults to 10.

Yields:

T – Matching resource.

Raises:

SAPResponseError – If the read encountered an error.

async read_first(resource_cls: type[T], *, filters: BooleanOperator | LogicalOperator | str | None = None, order_by: list[str] | None = None) T[source]

Read the first matching resource.

A convenience method for await anext(read_all(…)) with page_size=1.

Parameters:
  • resource_cls (type[T]) – The type of the resource to read.

  • filters (BooleanOperator | LogicalOperator | str, optional) – The filters to apply.

  • order_by (list[str], optional) – The fields to order by.

Returns:

The first matching resource.

Return type:

T

Raises:

SAPNotFoundError – If no matching resource is found.

async read_seq(resource_cls: type[T], seq: str) T[source]

Read the specified resource.

Parameters:
  • resource_cls (type[T]) – The type of the resource to read.

  • seq (str) – The unique identifier of the resource.

Returns:

The specified resource. Raises an exception if the resource is not found.

Return type:

T

Raises:
  • SAPBadRequestError – If the resource was not found.

  • SAPResponseError – If the read encountered an error.

async read(resource: T) T[source]

Reload a fully initiated resource.

A convenience method for await read_seq(resource.__class__, resource.seq).

Parameters:

resource (T) – The fully initiated resource.

Returns:

The fully initiated resource.

Return type:

T

Raises:

SAPNotFoundError – If the resource does not contain a unique identifier.

Example

When running a pipeline job, you can wait for the job to complete:

pipeline = await run_pipeline(job)
while pipeline.state != PipelineState.Done:
    await asyncio.sleep(30)
    pipeline = client.read(pipeline)
async run_pipeline(job: _PipelineJob) Pipeline[source]

Run a pipeline and retrieves the created Pipeline.

Parameters:

job (model.pipeline._PipelineJob) – The pipeline job to run.

Returns:

The created Pipeline.

Return type:

model.Pipeline

Raises:

SAPResponseError – If the pipeline failed to run.

async cancel_pipeline(job: Pipeline) bool[source]

Cancel a running pipeline.

Parameters:

job (model.Pipeline) – The running pipeline job to cancel.

Returns:

True if the pipeline was successfully canceled. Raises an exception

othwise.

Return type:

bool

Raises:

SAPResponseError – If the deletion encountered an error.