Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/public-api/apify-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3530,6 +3530,7 @@ export interface RunChargeOptions extends TimeoutOptions {
count?: number;
eventName: string;
idempotencyKey?: string;
requestId?: string;
}

// @public
Expand Down
10 changes: 10 additions & 0 deletions src/resource_clients/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const chargeOptionsSchema = z.strictObject({
eventName: z.string(),
count: z.number().default(1),
idempotencyKey: z.string().optional(),
requestId: z.string().optional(),
...timeoutOptionsShape,
});
const waitForFinishOptionsSchema = z.strictObject({ waitSecs: z.number().optional(), ...timeoutOptionsShape });
Expand Down Expand Up @@ -342,6 +343,7 @@ export class RunClient extends ResourceClient {
* @param options.eventName - **Required.** Name of the event to charge for.
* @param options.count - Number of times to charge the event. Default is 1.
* @param options.idempotencyKey - Optional key to ensure the charge is not duplicated. If not provided, one is auto-generated.
* @param options.requestId - ID of the Server Actor request being charged, from the `X-Actor-Request-ID` header of the incoming request. Required for multi-tenant Server Actor runs.
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
* @returns Empty response object.
* @see https://docs.apify.com/api/v2/post-charge-run
Expand All @@ -353,6 +355,7 @@ export class RunClient extends ResourceClient {
count,
idempotencyKey: providedIdempotencyKey,
timeoutSecs = 'short',
requestId,
signal,
} = parseArgument(options, chargeOptionsSchema, 'RunChargeOptions');

Expand All @@ -366,6 +369,7 @@ export class RunClient extends ResourceClient {
data: {
eventName,
count,
requestId,
},
headers: {
[RUN_CHARGE_IDEMPOTENCY_HEADER]: idempotencyKey,
Expand Down Expand Up @@ -724,6 +728,12 @@ export interface RunChargeOptions extends TimeoutOptions {
count?: number;
/** Defaults to runId-eventName-timestamp */
idempotencyKey?: string;
Comment thread
janbuchar marked this conversation as resolved.
Resolved
/**
* ID of the Server Actor request being charged, taken from the `X-Actor-Request-ID` header of the incoming request.
* Required for multi-tenant Server Actor runs, where it maps the charge to the caller's account instead of the account that started the run.
* Ignored elsewhere.
*/
requestId?: string;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion test/runs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,9 @@ describe('Run methods', () => {
test('charge() works', async () => {
const runId = 'some-run-id';

const res = await client.run(runId).charge({ eventName: 'some-event' });
const res = await client.run(runId).charge({ eventName: 'some-event', requestId: 'some-request-id' });
expect(res.status).toEqual(200);
validateRequest({ body: { eventName: 'some-event', count: 1, requestId: 'some-request-id' } });

// Assert on the error type and the structured issue, since zod owns the wording.
const error = await client
Expand Down
Loading