rustsf 0.1.1

Salesforce SDK for Rust, supports the latest API version 68.0, (Winter 2026)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
//! # Salesforce Bulk API v1 for high-volume data operations.
//!
//! This module provides a client for interacting with Salesforce's Bulk API (version 1.0).
//! The Bulk API is optimized for processing large sets of data asynchronously.
//!
//! ## Overview
//!
//! The `BulkApi` struct provides methods for:
//! - Creating and managing bulk jobs
//! - Adding batches to jobs with CSV data
//! - Monitoring batch and job status
//! - Retrieving results from completed batches
//! - Closing and aborting jobs
//!
//! ## Example
//!
//! ```rust,ignore
//! use rustsf::{Client, BulkApi};
//! use serde::Serialize;
//!
//! #[derive(Serialize)]
//! struct JobParams {
//!     operation: String,
//!     object: String,
//!     content_type: String,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//!     let mut client= Client::new(Credentials::new()).await?;
//!     // Perform client...
//!     
//!     let mut bulk_api = BulkApi::new(client);
//!     
//!     // Create a job
//!     let params = JobParams {
//!         operation: "insert".to_string(),
//!         object: "Account".to_string(),
//!         content_type: "CSV".to_string(),
//!     };
//!     let job_response = bulk_api.create_job(params).await?;
//!     
//!     // Add batch data
//!     let csv_data = b"Name\nTest Account".to_vec();
//!     let batch_response = bulk_api.add_batch_job("job_id", csv_data).await?;
//!     
//!     // Close the job
//!     bulk_api.close_job("job_id").await?;
//!     
//!     Ok(())
//! }
//! ```
//!
//! ## API Documentation
//!
//! For more information about Salesforce Bulk API, see:
//! <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/>

use crate::client::Client;
use crate::errors::Error;
use reqwest::Response;
use serde::Serialize;
use std::collections::HashMap;
use std::fmt::Debug;

pub struct BulkApi {
	pub(crate) client: Client,
}

impl BulkApi {
	/// Creates a new instance of the `BulkApi` struct.
	///
	/// # Arguments
	///
	/// * `client` - A `Client` instance used to perform API requests.
	///
	/// # Returns
	///
	/// A new `BulkApi` instance initialized with the provided `Client`.
	///
	/// # Example
	///
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///     let bulk_api = BulkApi::new(client);
	/// }
	/// ```
	pub fn new(client: Client) -> Self {
		BulkApi { client }
	}

	/// Constructs the base path URL for the asynchronous service endpoint.
	///
	/// # Returns
	///
	/// * `Ok(String)` - A string representing the constructed base path URL.
	/// * `Err(Error::NotLoggedIn)` - If the `instance_url` is not available, indicating the user is not logged in.
	///
	/// The method combines the instance URL and version from the client to construct
	/// the endpoint for asynchronous services.
	///
	/// # Errors
	///
	/// - Returns an `Error::NotLoggedIn` if the `instance_url` is not set, which
	///   likely means the client is not authenticated.
	///
	/// # Example
	/// ```rust,ignore
	///     let base_path = bulk_api.base_path()?;
	///     println!("Base path: {}", base_path);
	/// ```
	fn base_path(&self) -> String {
		let instance_url = self.client.instance_url();

		format!("{}/services/async/{}", instance_url, crate::client::DEFAULT_API_VERSION)
	}

	/// Asynchronously creates a new job with the specified parameters.
	///
	/// This method sends a POST request to the "/job" endpoint using the provided parameters
	/// and client headers to create a new job resource.
	///
	/// # Type Parameters
	/// - `T`: The type of the payload to be serialized and sent as the request body.
	///         Must implement the `Serialize` trait from `serde`.
	///
	/// # Parameters
	/// - `params`: The parameters for the job creation, which will be serialized into the request body.
	///
	/// # Returns
	/// - `Ok(Response)`: If the job creation is successful, returns the server's response wrapped in `Ok`.
	/// - `Err(Error)`: If an issue occurs (e.g., serialization error, network error, or invalid headers),
	///   returns an `Error` wrapped in `Err`.
	///
	/// # Errors
	/// - Returns an error if the `base_path` or `get_auth_headers` methods fail (e.g., missing or invalid credentials).
	/// - Returns an error if the HTTP client encounters an issue during the POST request.
	///
	/// # Example
	/// ```rust
	/// use serde::Serialize;
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[derive(Serialize, Debug)]
	/// struct JobParams {
	///     name: String,
	///     priority: u8,
	/// }
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let params = JobParams {
	///         name: String::from("example-job"),
	///         priority: 5,
	///     };
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     let response = bulk_api.create_job(params).await;
	///     match response {
	///         Ok(resp) => println!("Job created successfully: {:?}", resp),
	///         Err(err) => eprintln!("Failed to create job: {}", err),
	///     }
	/// }
	/// ```
	///
	/// # Notes
	/// - Ensure that the API client is properly initialized with valid credentials
	///   before calling this method.
	/// - The format of the `params` must adhere to the API's expectations for job creation.
	///
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_jobs_create.htm>
	pub async fn create_job<T: Serialize + Debug>(&mut self, params: T) -> Result<Response, Error> {
		let resource_url = format!("{}/job", self.base_path());
		let headers = self.get_auth_headers().await?;
		self.client.post_json(&resource_url, &params, &headers).await
	}

	/// Asynchronously adds a batch job to the specified job ID with the provided CSV data.
	///
	/// # Parameters
	/// - `job_id`: A string slice (`&str`) representing the unique identifier of the job
	///   to which the batch job will be added.
	/// - `csv`: A vector of bytes (`Vec<u8>`) containing the CSV data that will be sent
	///   with the batch job.
	///
	/// # Returns
	/// - `Ok(Response)`: A `Response` object containing the server's response if the
	///   operation is successful.
	/// - `Err(Error)`: An `Error` object if an error occurs during the operation, such as
	///   client issues, network errors, or invalid input.
	///
	/// # Errors
	/// This function can return errors under the following conditions:
	/// - If constructing the base path (`self.base_path()`) fails.
	/// - If generating the client headers (`self.get_auth_headers()`) fails.
	/// - If the HTTP POST request fails due to network issues or server-side errors.
	///
	/// # Example
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     let job_id = "12345";
	///     let csv_data = vec![104, 101, 108, 108, 111]; // Example CSV bytes ("hello")
	///     match bulk_api.add_batch_job(job_id, csv_data).await {
	///         Ok(response) => {
	///             println!("Batch job added successfully: {:?}", response);
	///         }
	///         Err(error) => {
	///             eprintln!("Failed to add batch job: {:?}", error);
	///         }
	///     }
	/// }
	/// ```
	///
	/// # Note
	/// - The `Content-Type` header for this request is automatically set to `text/csv`.
	/// - Ensure that the `self.client` is properly initialized and authenticated
	///   before calling this function.
	///
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_quickstart_add_batch.htm>
	pub async fn add_batch_job(&mut self, job_id: &str, csv: Vec<u8>) -> Result<Response, Error> {
		let resource_url = format!("{}/job/{}/batch", self.base_path(), job_id);
		let mut headers = self.get_auth_headers().await?;
		headers.insert("Content-Type".to_string(), "text/csv".to_string());
		self.client.post(&resource_url, csv, &headers).await
	}

	/// Fetches the details of a specific batch associated with a given job.
	///
	/// This asynchronous function retrieves data for the specified batch, identified by its `batch_id`,
	/// which is associated with the provided `job_id`. The function constructs the appropriate URL
	/// using the job and batch identifiers and sends a GET request to the remote service.
	/// The request includes client headers for authorization.
	///
	/// # Parameters
	/// - `job_id`: A reference to a string slice representing the unique identifier of the job.
	/// - `batch_id`: A reference to a string slice representing the unique identifier of the batch.
	///
	/// # Returns
	/// - `Ok(Response)`: On success, returns a `Response` object containing the batch details retrieved
	///   from the remote service.
	/// - `Err(Error)`: If an error occurs during URL construction, header generation, or the HTTP request,
	///   an error of type `Error` is returned.
	///
	/// # Errors
	/// This function can return an error in the following cases:
	/// - If the base path cannot be determined (`self.base_path()` fails).
	/// - If client headers cannot be generated (`self.get_auth_headers()` fails).
	/// - If the HTTP request to the remote service fails.
	///
	/// # Example
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     let response = bulk_api.get_batch("123", "456").await;
	///     match response {
	///         Ok(data) => println!("Batch details: {:?}", data),
	///         Err(e) => eprintln!("Error fetching batch: {:?}", e),
	///     }
	/// }
	/// ```
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_quickstart_check_status.htm>
	pub async fn get_batch(&mut self, job_id: &str, batch_id: &str) -> Result<Response, Error> {
		let resource_url = format!("{}/job/{}/batch/{}/", self.base_path(), job_id, batch_id);
		let headers = self.get_auth_headers().await?;
		self.client.get_raw(&resource_url, &headers).await
	}

	/// Closes a job by updating its state to "Closed".
	///
	/// # Parameters
	/// - `job_id`: A string slice that holds the unique identifier of the job to be closed.
	///
	/// # Returns
	/// An asynchronous `Result` containing:
	/// - `Response`: The server's response if the job closure is successful.
	/// - `Error`: An error indicating what went wrong (e.g., network issues, invalid job ID, or
	/// client failure).
	///
	/// # Errors
	/// This function will return an error in the following cases:
	/// - If `base_path` fails to retrieve the base URL for the request.
	/// - If `get_auth_headers` fails to retrieve the necessary client headers.
	/// - If the HTTP POST request to update the job state fails.
	///
	/// # Example
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     let job_id = "12345";
	///     match bulk_api.close_job(job_id).await {
	///         Ok(response) => println!("Job successfully closed: {:?}", response),
	///         Err(err) => eprintln!("Failed to close job: {:?}", err),
	///     }
	///     Ok(())
	///  }
	/// ```
	///
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_jobs_close.htm>
	pub async fn close_job(&mut self, job_id: &str) -> Result<Response, Error> {
		let resource_url = format!("{}/job/{}", self.base_path(), job_id);
		let headers = self.get_auth_headers().await?;
		let mut params = HashMap::new();
		params.insert("state", "Closed");
		self.client.post_json(&resource_url, &params, &headers).await
	}

	/// Asynchronously fetches the details of a specific job from the server.
	///
	/// # Arguments
	///
	/// * `job_id` - A string slice that holds the unique identifier of the job.
	///
	/// # Returns
	///
	/// * `Result<Response, Error>` -
	///     * On success, returns a `Response` object containing the job details.
	///     * On failure, returns an `Error` object detailing what went wrong.
	///
	/// # Errors
	///
	/// This function will return an error in the following cases:
	/// * If the `base_path()` method fails to generate a valid base URL.
	/// * If the `get_auth_headers()` method fails to generate the required client headers.
	/// * If the HTTP GET request to the server fails.
	///
	/// # Examples
	///
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     match bulk_api.get_job_details("12345").await {
	///         Ok(response) => println!("Job details: {:?}", response),
	///         Err(e) => eprintln!("Failed to fetch job details: {:?}", e),
	///     }
	/// }
	/// ```
	///
	/// # Remarks
	///
	/// The function constructs the resource URL by appending the job ID to the base path.
	/// It adds the required client headers before sending the GET request using the HTTP client.
	///
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_jobs_get_details.htm>
	pub async fn get_job_details(&mut self, job_id: &str) -> Result<Response, Error> {
		let resource_url = format!("{}/job/{}", self.base_path(), job_id);
		let headers = self.get_auth_headers().await?;
		self.client.get_raw(&resource_url, &headers).await
	}

	/// Retrieves the batches associated with a specific job in an asynchronous manner.
	///
	/// # Arguments
	///
	/// * `job_id` - A string slice that identifies the job for which the batches are to be retrieved.
	/// * `content_type` - A string slice representing the content type to set for the request headers.
	///
	/// # Returns
	///
	/// * `Result<Response, Error>` - Returns a `Response` on success, which contains the raw HTTP response or an `Error` on failure.
	///
	/// # Errors
	///
	/// This function will return an `Error` if:
	/// - The `base_path` method fails to generate the base URL.
	/// - The client headers cannot be generated.
	/// - The HTTP GET request to the resource URL fails.
	///
	/// # Example
	///
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     let job_id = "12345";
	///     let content_type = "application/json";
	///
	///     match bulk_api.get_batches(job_id, content_type).await {
	///         Ok(response) => {
	///             println!("Successfully retrieved batches: {:?}", response);
	///         },
	///         Err(e) => {
	///             eprintln!("Error occurred while retrieving batches: {:?}", e);
	///         },
	///     }
	/// }
	/// ```
	///
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_batches_get_info_all.htm>
	pub async fn get_batches(&mut self, job_id: &str, content_type: &str) -> Result<Response, Error> {
		let resource_url = format!("{}/job/{}/batch", self.base_path(), job_id);
		let mut headers = self.get_auth_headers().await?;
		headers.insert("Content-Type".to_string(), content_type.to_string());
		self.client.get_raw(&resource_url, &headers).await
	}

	/// Asynchronously retrieves the list of results for a specific job and batch.
	///
	/// # Parameters
	/// - `job_id`: A string slice that holds the unique identifier of the job.
	/// - `batch_id`: A string slice that holds the unique identifier of the batch associated with the job.
	/// - `content_type`: A string slice specifying the desired content type for the response.
	///
	/// # Returns
	/// - `Ok(Response)`: A successful HTTP response containing the result list for the specified job and batch.
	/// - `Err(Error)`: An error if the operation fails, such as issues with client, URL construction, or the HTTP request.
	///
	/// # Errors
	/// This function may return an error in the following cases:
	/// - If the `base_path` retrieval fails.
	/// - If there's an issue generating the client headers.
	/// - If the HTTP `GET` request fails (e.g., network issues or a non-success HTTP status).
	///
	/// # Example
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     let job_id = "12345";
	///     let batch_id = "67890";
	///     let content_type = "application/json";
	///    
	///     match bulk_api.get_result_list(job_id, batch_id, content_type).await {
	///         Ok(response) => {
	///             println!("Successfully retrieved results: {:?}", response);
	///         }
	///         Err(err) => {
	///             eprintln!("Error retrieving results: {:?}", err);
	///         }
	///     }
	/// }
	/// ```
	///
	/// # Notes
	/// - This function uses the `self.base_path()` method to build the URL endpoint.
	/// - It appends necessary authorization headers using `self.get_auth_headers()`.
	/// - The request is dispatched via the `client.get_raw` method.
	///
	/// # Dependencies
	/// Ensure that the asynchronous runtime (e.g., `tokio` or `async-std`) is properly configured to execute this function.
	///
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_batches_get_results.htm>
	pub async fn get_result_list(
		&mut self,
		job_id: &str,
		batch_id: &str,
		content_type: &str,
	) -> Result<Response, Error> {
		let resource_url = format!("{}/job/{}/batch/{}/result", self.base_path(), job_id, batch_id);
		let mut headers = self.get_auth_headers().await?;
		headers.insert("Content-Type".to_string(), content_type.to_string());
		self.client.get_raw(&resource_url, &headers).await
	}

	/// Fetches the result of a specific job batch operation asynchronously.
	///
	/// This function builds the URL for accessing the result of a job by taking
	/// the job ID, batch ID, and result ID, and it includes the necessary
	/// client headers for the request. The result is retrieved
	/// using an HTTP GET request.
	///
	/// # Arguments
	///
	/// * `job_id` - A string slice that holds the unique identifier of the job.
	/// * `batch_id` - A string slice that represents the batch ID within the job.
	/// * `result_id` - A string slice that specifies the ID of the desired result.
	///
	/// # Returns
	///
	/// * `Ok(Response)` - The raw response containing the result data if the operation is successful.
	/// * `Err(Error)` - If there is an error during URL construction, header generation,
	///    or while making the HTTP request.
	///
	/// # Errors
	///
	/// This function will return an error in the following cases:
	/// * If the base URL cannot be retrieved through `self.base_path()`.
	/// * If there is an issue generating client headers via `self.get_auth_headers()`.
	/// * If the HTTP GET request fails.
	///
	/// # Example
	///
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     match bulk_api.get_result("job123", "batch456", "result789").await {
	///         Ok(response) => println!("Result fetched: {:?}", response),
	///         Err(error) => println!("Failed to fetch result: {:?}", error),
	///     }
	/// }
	/// ```
	///
	/// # Notes
	///
	/// Ensure that the `client` instance is properly configured with the
	/// required base path and client capabilities before calling this function.
	///
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_code_curl_walkthrough_pk_chunking.htm>
	pub async fn get_result(&mut self, job_id: &str, batch_id: &str, result_id: &str) -> Result<Response, Error> {
		let resource_url = format!(
			"{}/job/{}/batch/{}/result/{}",
			self.base_path(),
			job_id,
			batch_id,
			result_id
		);
		let mut headers = self.get_auth_headers().await?;
		headers.insert("Content-Type".to_string(), "application/xml".to_string());
		self.client.get_raw(&resource_url, &headers).await
	}

	/// Aborts a job with the specified `job_id`.
	///
	/// This function sends a `POST` request to the resource URL corresponding to the job,
	/// updating its state to "Aborted". The request includes client headers
	/// and a JSON content type header.
	///
	/// # Arguments
	///
	/// * `job_id` - A string slice representing the unique identifier of the job
	///              to be aborted.
	///
	/// # Returns
	///
	/// * `Result<Response, Error>` - On success, returns a `Response` object containing
	///                                the server's response to the `POST` request.
	///                                On failure, returns an `Error` describing the problem.
	///
	/// # Errors
	///
	/// This function can return an `Error` if:
	/// * The base path for the URL cannot be determined.
	/// * Authentication headers cannot be generated.
	/// * The HTTP client fails to complete the `POST` request.
	///
	/// # Example
	///
	/// ```rust
	/// use rustsf::{Client, Credentials, BulkApi};
	/// use anyhow::Result;
	///
	/// #[tokio::main]
	/// async fn main() {
	///     let mut client= Client::new(Credentials::new()).await?;
	///     // Authentication logic...
	///
	///     let mut bulk_api = BulkApi::new(client);
	///     match bulk_api.abort_job("12345").await {
	///         Ok(response) => println!("Job aborted successfully: {:?}", response),
	///         Err(error) => eprintln!("Failed to abort job: {:?}", error),
	///     }
	/// }
	/// ```
	///
	/// # See
	/// <https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_jobs_abort.htm>
	pub async fn abort_job(&mut self, job_id: &str) -> Result<Response, Error> {
		let resource_url = format!("{}/job/{}", self.base_path(), job_id);
		let mut headers = self.get_auth_headers().await?;
		headers.insert("Content-Type".to_string(), "application/json".to_string());

		let mut params = HashMap::new();
		params.insert("state", "Aborted");

		self.client.post_json(&resource_url, &params, &headers).await
	}

	/// Retrieves the client headers required for making API requests.
	///
	/// # Returns
	/// * `Ok(Vec<(String, String)>)` - A vector of header key-value pairs, where each pair represents
	///   an HTTP header. Currently, the implementation includes the `X-SFDC-Session` header
	///   with the access token as its value.
	/// * `Err(Error)` - Returns an error if the access token is not available (e.g., when the
	///   user is not logged in).
	///
	/// # Errors
	/// * `Error::NotLoggedIn` - Returned if the `access_token` field of the `client` is `None`.
	///
	/// # Notes
	/// * The `X-SFDC-Session` header is specifically required for API version 1 requests.
	async fn get_auth_headers(&self) -> Result<HashMap<String, String>, Error> {
		let token = self.client.access_token().await?;
		let mut headers = HashMap::new();
		headers.insert("X-SFDC-Session".to_string(), token);
		Ok(headers)
	}
}