Pulling Profit And Loss Information in Bulk - Sellercloud API Docs
Pulling Profit And Loss Information in Bulk
Overview
In order to get information about profit and loss for multiple orders, you can consume the endpoint presented in this article. In order to consume it, you must:
- Be authenticated user
For information on how you can authenticate, see: Authentication
As soon as you do authentication and receive a valid token, it needs to be passed on every call to the server.
Endpoint
Example for such endpoint for TT server is:
https://tt.api.sellercloud.com/api/Orders/ProfitAndLoss
For your server endpoint will be:
https://{your_server_id}.api.sellercloud.com/api/Orders/ProfitAndLoss
Request Payload
{
"Orders": [
5828302
]
}
Response
[
{
"OrderItems": [
{
"ProductID": "variation-10-foot-ca",
"QtySold": 3,
"OrderUnitSiteCost": 0,
"OrderSiteCost": 0,
"ProductUnitSiteCost": 0,
"ProductSiteCost": 0,
"SellingPrice": 0,
"RefundTotal": 2,
"ChannelCommission": 0,
"TransactionFee": 0,
"FinalCostTotal": 12,
"Profit": -12,
"ProfitPercent": 0
}
],
"OrderID": 5828302,
"PaymentStatus": 30,
"ShippingStatus": 3,
"ShipDate": "2021-01-02T04:01:58.777+02:00",
"Channel": 0,
"CustomerID": 127345,
"IsTaxCollectedByMarketplace": false,
"SettlementDataAvailable": false,
"ItemCost": "0",
"ItemCostUsd": "0",
"PostingFee": "0",
"PostingFeeUsd": "0",
"Comission": "0",
"ComissionUsd": "0",
"TransportationFee": "0",
"TransactionFee": "0",
"TransactionFeeUsd": "0",
"ShippingCost": "12",
"ShippingCostUsd": "12",
"FbaOrderHandling": "0",
"FbaPickAndPack": "0",
"FbaShippingChargeback": "0",
"FbaGiftWrapChargeback": "0",
"FbaWeightHandling": "0",
"Tax": "0",
"TaxUsd": "0",
"Promotion": "0",
"PromotionUsd": "0",
"Rebates": "0",
"RebatesUsd": "0",
"OrderCost": "12",
"OrderCostUsd": "12",
"Payments": null,
"PaymentsUsd": null,
"Adjustments": "0",
"AdjustmentsUsd": "0",
"DropShipFee": "0",
"DropShipFeeUsd": "0",
"ShippingClaim": "0",
"ProfitLoss": "-9",
"ProfitLossPercentage": "-140.0 %",
"ProfitLossUsd": "-9",
"ProfitLossForParentOrder": null,
"QbExported": false,
"CurrencyCode": 0,
"FirstSalesRep": null,
"SecondSalesRep": null,
"ThirdSalesRep": null
}
]
| Field | Description |
| OrderID | ID of the sales order. |
| OrderItems | Array of order items information related to fees, commissions, prices, costs for each item. |
| CurrencyCode | Currency code of the order. |
| PaymentStatus | All available payment statuses can be found here: https://developer.sellercloud.com/dev-article/payment-status/ |
| ShippingStatus | All available shipping statuses can be found here: https://developer.sellercloud.com/dev-article/order-shipping-status/ |
| ShipDate | When order has been shipped. |
| Channel | Codes for all channels can be found here: https://developer.sellercloud.com/dev-article/channels/ |
| CustomerID | ID of the customer. That information can be used for doing other calls for retrieving additional information for that customer. More info here: https://developer.sellercloud.com/dev-article/get-single-customer/ |
| DropshipFee | Dropshipping fee. If orders is not using USD, then dropshipping fee will be calculated in the correct order’s currency according to the currency rates. |
| DropshipFeeUsd | Dropshipping fee in USD. |
| Commission | Commission fee. If order is from Amazon or FBA order, then commissions is “N/A” If orders is not using USD, then commission will be calculated in the correct order’s currency according to the currency rates. |
Response Status Codes
| #### 200 | OK |
| #### 401 | Unauthorized |
| #### 500 | Internal Server Error |
Demo in c#
Authentication
public class LoginResponse
{
public string token_type { get; set; }
public string access_token { get; set; }
public DateTime? validFrom { get; set; }
public DateTime? validTo { get; set; }
}
public interface IAuthenticationClient
{
string Login(string baseUri, LoginRequest request);
}
public class LoginRequest
{
public LoginRequest(string username, string password)
{
this.Username = username;
this.Password = password;
}
public string Username { get; }
public string Password { get; }
}
public class AuthenticationClient : IAuthenticationClient
{
public string Login(string baseUri, LoginRequest loginRequest)
{
using (var client = new HttpClient())
using (var request = new HttpRequestMessage(HttpMethod.Post, $"{baseUri}/api/token"))
{
var json = JsonConvert.SerializeObject(loginRequest);
using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
{
request.Content = stringContent;
var responseMessage = client.SendAsync(request).Result;
var content = responseMessage.Content.ReadAsStringAsync().Result;
var response = JsonConvert.DeserializeObject(content);
return response.access_token;
}
}
}
}
Getting Profit And Loss
public class GetProfitAndLossRequest
{
public IEnumerable Orders { get; set; }
}
string baseUri = "http://{server_id}.api.sellercloud.com/rest";
string url = $"{baseUri}/api/Orders/ProfitAndLoss";
string username = "{your_username}";
string password = "{your_password}";
IAuthenticationClient authenticationClient = new AuthenticationClient();
string token = authenticationClient.Login(baseUri, new LoginRequest(username, password));
var content = new GetProfitAndLossRequest()
{
Orders = realOrders
};
using (var client = new HttpClient())
using (var request = new HttpRequestMessage(HttpMethod.Post, url))
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var json = JsonConvert.SerializeObject(content);
using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
{
request.Content = stringContent;
var responseMessage = await client.SendAsync(request);
var jsonContent = await responseMessage.Content.ReadAsStringAsync();
}
}