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:
objectAsynchronous 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.
- async _request(method: HTTPMethod, uri: str, params: dict | None = None, json: list | None = None) dict[str, Any][source]
Send a request.
- Parameters:
- Returns:
The JSON response.
- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- Raises:
SAPResponseError – If the deletion encountered an error.