PHP code example of michaelbutler / phposh

1. Go to this page and download the library: Download michaelbutler/phposh library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

michaelbutler / phposh example snippets




 The way this works is, it needs the cookie data from your logged-in Poshmark browser session.
 * Simple way to get this is:
 * - Log in to www.poshmark.com
 * - Press Ctrl/Command + Shift + e (Firefox)
 *      - In Chrome, Ctrl/Command + Shift + i then click Network tab
 * - Refresh the page
 * - Right click the very top web request in the list and choose Copy as cURL
 * - Paste into a Text Document and then find the information after `Cookie:`
 * - If you ever get an error, repeat the steps above to get the latest cookie data.
 */

$cookieString = "ps=....; _csrf=....; ...";
$pmService = new \PHPosh\Provider\Poshmark\PoshmarkService($cookieString);

$allItems = $pmService->getItems();

foreach ($allItems as $item) {
    echo sprintf("itemId: %s - %s (%s)\n", $item->getId(), $item->getTitle(), $item->getPrice());
}

// Print the raw data array as provided by Poshmark
print_r($allItems[0]->getRawData());

$userUuid = 'abc123def456....'; // userUuid can be found in the HTML code of a user's closet web page
$username = 'coolshop';
$allItems = $pmService->getItems($userUuid, $username);

foreach ($allItems as $item) {
    echo sprintf("itemId: %s - %s (%s)\n", $item->getId(), $item->getTitle(), $item->getPrice());
}

// Use the itemId found via getItems or from an order
$item = $pmService->getItem('abc123def456....');

echo sprintf("itemId: %s - %s (%s)\n", $item->getId(), $item->getTitle(), $item->getPrice());

// The item's raw data element gives you all possible data provided by Poshmark,
// as a nested array map.
$rawData = $item->getRawData();

echo "Department: " . $rawData['department']['display'] . "\n";
echo "Num. Shares: " . $rawData['aggregates']['shares'] . "\n";

print_r($rawData);

// Get 50 most recent orders.
// Not all details are available in the order summaries.
$orders = $pmService->getOrderSummaries(50);

foreach ($orders as $order) {
    echo sprintf("orderId: %s - %s (%s)\n", $order->getId(), $order->getTitle(), $order->getBuyerUsername());
    echo sprintf("Status: %s, Num. Items: %d\n", $order->getOrderStatus(), $order->getItemCount());
}

// Following example above
$orderId = $orders[0]->getId();
$details = $pmService->getOrderDetail($orderId);

echo "\n";
echo sprintf("Order Title: %s\n", $details->getTitle());
echo sprintf("Buyer: %s\n", $details->getBuyerUsername());
echo sprintf("Total: %s\n", $details->getOrderTotal());
echo sprintf("Earnings: %s\n", $details->getEarnings());

echo "Items:\n";

foreach ($details->getItems() as $index => $item) {
    echo sprintf("%d: %s [%s] (%s)\n", $index + 1, $item->getTitle(), $item->getSize(), $item->getPrice());
}

$itemFields = [
    // Only the below 4 fields are currently supported. Send at least one, multiple supported.
    'title' => 'Calvin Klein Jeans',
    'price' => '29.00 USD', // also "$29.00" is supported
    'description' => 'Great condition very comfortable jeans. One small tear on the left front pocket',
    'brand' => 'Calvin Klein',
];

try {
    $result = $pmService->updateItem('abc123def456...', $itemFields);
} catch (\PHPosh\Exception\DataException $e) {
    echo "ERROR: Item abc123def456... failed to update!! " . $e->getMessage();
    exit(1); 
}

echo "SUCCESS: Item abc123def456... updated!!\n";