Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendOfferToInterestedBuyers Response is not JSON data error #1

Open
compadvance opened this issue Jan 12, 2024 · 1 comment
Open

sendOfferToInterestedBuyers Response is not JSON data error #1

compadvance opened this issue Jan 12, 2024 · 1 comment

Comments

@compadvance
Copy link

Hi mate , working on it recently , whatever I try this requests wont be successful , Response is not JSON data most commonly
whenever I use $res = $apiInstance->sendOfferToInterestedBuyers($this->ebayId,$offerRequest,$contentType); or $res = $apiInstance->sendOfferToInterestedBuyers($this->ebayId,$jsonString,$contentType); where $jsonString = json_encode($offerRequest);
What I missing , generated json file match ebay requirements perfectly and all required fields are there . Any hint would be much appreciated. Emil

public function send_Ebay_Offers($params){

$contentType = 'Content-type:application/json';
    //$offer_duration = ['unit'=>DAY,'value'=>2];
    //$offered_price  = ['currency'=>'GBP','value'=>$params['offerPrice']];
    $offered_price = ['value' => $params['offerPrice']];

    foreach ($params['listing_IDs'] as $listingID) {
        $offeredItems = [['listingID' => $listingID, 'price' => ['value' => $params['offerPrice']], 'quantity' => 1]];

        $offerRequest = new \macropage\SDKs\ebay\rest\negotiation\Model\CreateOffersRequest();
        $offerRequest->setAllowCounterOffer($params['allowCounterOffer']);
        $offerRequest->setMessage($params['message']);
        $offerRequest->setOfferedItems($offeredItems);

       // var_dump($offerRequest);die();
        //$jsonString = json_encode($offerRequest);
        $apiInstance = $this->apiInstance;
        
        try {
            $res = $apiInstance->sendOfferToInterestedBuyers($this->ebayId,$offerRequest,$contentType);
            print_r($res);
        } catch (\macropage\SDKs\ebay\rest\negotiation\ApiException $e) {
            // Capture and decode the error response
            $errorResponse = $e->getResponseBody(); // Get the raw response body
            $errorDetails = json_decode($errorResponse, true); // Decode JSON response to an associative array
            echo "EMIL Error: " . $errorDetails['errors'][0]['message'] ?? 'Unknown error';
        } catch (\Exception $e) {
            // Handle other exceptions (if any)
            echo "EMIL Exception: " . $e->getMessage();
        }
    }
}
@michabbb
Copy link
Owner

hi there,
without knowing how the ebay response looks like it´s nearly impossible to help you.
first make sure you are using a correct oauth token that has the correct scopes and is valid.

here´s how I am doing that call, maybe it helps:

use GuzzleHttp\Client;

public function __construct(string $ebay_account_name)
    {
        $this->apiConfig   = $this->getEbayToken($ebay_account_name);
        $this->apiInstance = new OfferApi(
            new Client(),
            Configuration::getDefaultConfiguration()->setAccessToken($this->apiConfig->token)
        );
    }

public function sendOfferToInterestedBuyers(int $itemid): apiError|SendOfferToInterestedBuyersCollectionResponse
    {
        $offeredItem = new OfferedItem();
        $offeredItem->setListingId($itemid);
        $offeredItem->setQuantity(1);
        $offeredItem->setDiscountPercentage(config('discount.percent'));
        $offeredItems[] = $offeredItem;

        $createdOfferRequests = new CreateOffersRequest();
        $createdOfferRequests->setMessage(sprintf(config('discount.text'), config('discount.percent'), config('discount.duration.value')));
        $createdOfferRequests->setAllowCounterOffer(false);
        $createdOfferRequests->setOfferDuration(
            new TimeDuration(
                [
                    'unit'  => config('discount.duration.unit'),
                    'value' => (string)config('discount.duration.value')
                ]
            )
        );
        $createdOfferRequests->setOfferedItems($offeredItems);

        try {
            return $this->apiInstance->sendOfferToInterestedBuyers($this->apiConfig->marketplace, $createdOfferRequests);
        } catch (ApiException $e) {
            Log::error($e->getResponseBody());
            return $this->parseErrors($e->getResponseBody());
        }
    }

maybe it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants