diff --git a/libpaket/src/tracking.rs b/libpaket/src/tracking.rs index 6db6418..08fd91e 100644 --- a/libpaket/src/tracking.rs +++ b/libpaket/src/tracking.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::{login::DHLIdToken, LibraryError, LibraryResult}; +use crate::{constants::web_user_agent, login::DHLIdToken, LibraryResult}; #[derive(Default)] pub struct TrackingParams { @@ -19,30 +19,38 @@ impl crate::WebClient { &self, params: TrackingParams, ids: Vec, - dhli: Option<&DHLIdToken>, + dhli: &DHLIdToken, ) -> LibraryResult> { let api_key = crate::www::api_key_header(); - let res = if let Some(dhli) = dhli { - let cookie_value = crate::utils::CookieHeaderValueBuilder::new() - .add_dhli(&dhli) - .add_dhlcs(&dhli) - .build_string(); - request!( - self.web_client, - endpoint_data_search, - query(&query_parameters_data_search(¶ms, ids)), - header(api_key.0, api_key.1), - header("cookie", cookie_value), - header("x-requested-with", "de.dhl.paket"), - header("sec-ch-ua-platform", "\"Android\""), - header("sec-ch-ua", r#""Chromium";v="122", "Not(A:Brand";v="24", "Android WebView";v="122""#), - header("sec-ch-ua-mobile", "?1"), - header("content-type", "application/json"), - header("accept", "application/json") - ) - } else { - return Err(LibraryError::InvalidArgument("only supported with a logged-in session".to_string())); - }; + let cookie_value = crate::utils::CookieHeaderValueBuilder::new() + .add_dhli(&dhli) + .add_dhlcs(&dhli) + .build_string(); + + let res = request!( + self.web_client, + endpoint_data_search, + query(&query_parameters_data_search(¶ms, ids)), + header(api_key.0, api_key.1), + header("cookie", cookie_value), + header("accept-language", "de-DE;q=1.0"), + header("x-requested-with", "de.dhl.paket"), + header("sec-ch-ua-platform", "\"Android\""), + header( + "sec-ch-ua", + r#""Chromium";v="122", "Not(A:Brand";v="24", "Android WebView";v="122""# + ), + header("sec-ch-ua-mobile", "?1"), + header("accept", "application/json"), + header("content-type", "application/json"), + header( + "referer", + "https://www.dhl.de/int-static/pdapp/spa/prod/ver5-SPA-VERFOLGEN.html" + ), + header("verfolgen-wg", "0"), + header("user-agent", web_user_agent()), + headers(crate::www::web_headers()) + ); let resp = parse_json_response!(res, Response); resp.into() @@ -418,7 +426,7 @@ fn query_parameters_data_search( let mut out = vec![ ("noRedirect".to_string(), "true".to_string()), ("cid".to_string(), "app".to_string()), - ]; + ]; if let Some(lang) = params.language.as_ref() { out.push(("language".to_string(), lang.clone()));