Go Back   Developer Program Forum > Sports API > PHP

PHP Discussions about the widely-used general-purpose scripting language PHP that is especially suited for Web development and can be embedded into HTML.

Post Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2011, 09:54 AM
Wongo Wongo is offline
Junior Member
 
Join Date: Oct 2009
Posts: 14
Default How to retrieve betId from place bets response

Hi, I'm confused by what I'm sure is a simple task but I can't see the wood for the trees...

I'm successfully placing bets using the following code:

Code:
$price = 1000;
$size = 2;
	
$bets = array();
$bets1['PlaceBets'] = array(
	'asianLineId' => 0, 
	'betType' => 'B', 
	'betCategoryype' => 'E',
	'betPersistenceType' => 'NONE',
	'marketId' => $eventID, 
	'price' => $price, 
	'selectionId' => $selectionID,
	'size' => $size,
	'bspLiability' => 0
);
						
$bets = array($bets1['PlaceBets']);
$placeBetsResp = $betfairlibrary->betfair_exchange_api->betfair_place_bets($sessionToken, $bets);
The $eventID and $selectionID indicated above are declared elsewhere in the script.

I want to be able to check that the betId was placed successfully by checking to see that it does not equal zero. If it is, I want to retrieve the error information contained within the response.

I presumed I could simple point to the corresponding array element with the following code, but when I do I receive an error.

Code:
$confirmedbetId = $placeBetsResp['Result']['betResults']['PlaceBetsResult'][0]['betId'];
The error received is:

Quote:
Fatal error: Cannot use object of type stdClass as array in /var/www/placebettest.php on line 85
What am I doing wrong?
  #2  
Old 11-23-2011, 05:31 AM
BigSprout BigSprout is offline
Member
 
Join Date: Feb 2011
Location: Qld, Australia
Posts: 66
Default

Wongo,
check here: https://docs.developer.betfair.com/b...MC.00008311-MC

If the bet is placed successfully then "success=true" else "False"

For a more detailed response check:
"resultCode" of type "PlaceBetsResultEnum"
Error messages range from "OK" to "What went wrong"

Hope this helps
  #3  
Old 11-23-2011, 08:49 AM
Wongo Wongo is offline
Junior Member
 
Join Date: Oct 2009
Posts: 14
Default

Thanks for the reply BigSprout

I've read the documentation you pointed to. My problem doesn't lie with what to check. It is my lack of knowledge on the php programming side. How do I reference any of the individual elements of the array that is returned?

If I use the php print_r() function I get the following (where the sessionToken and the betId fields have been edited by me):

Quote:
stdClass Object ( [Result] => stdClass Object ( [header] => stdClass Object ( [errorCode] => OK [minorErrorCode] => [sessionToken] => xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [timestamp] => 2011-11-23T09:37:53.058Z ) [betResults] => stdClass Object ( [PlaceBetsResult] => stdClass Object ( [averagePriceMatched] => 0 [betId] => yyyyyyyyyyyy [resultCode] => OK [sizeMatched] => 0 [success] => 1 ) ) [errorCode] => OK [minorErrorCode] => ) )
So, if I wanted to check the betId field, or, as you suggest, the success field, how do I go about it? As my original post indicates I thought I could use:

Code:
$confirmedbetId = $placeBetsResp['Result']['betResults']['PlaceBetsResult'][0]['betId'];
But that simply produces the error:

Quote:
Fatal error: Cannot use object of type stdClass as array in /var/www/placebettest.php on line 85
So clearly, it is the way in which I am trying to reference the individual array elements that has me stumped.

Thanks for you help.
  #4  
Old 11-23-2011, 11:29 AM
Wongo Wongo is offline
Junior Member
 
Join Date: Oct 2009
Posts: 14
Default

I got it sorted. I knew it must have been something simple:

Code:
$confirmedbetId = $placeBetsResp->Result->betResults->PlaceBetsResult->betId;
This works a treat and I can access the other elements in the same way.
  #5  
Old 04-16-2012, 03:33 PM
Tam's Loup Tam's Loup is offline
Junior Member
 
Join Date: Jan 2009
Posts: 21
Default

I'm new to PHP and am having trouble accessing the contents of the responses returned from the api functions.

For example:
$eventResponse = $betfair->betfair_global_api->betfair_get_all_event_types($loginResponseError[1]);
$eventName = $eventResponse->Result->eventTypeItems[0]->name;

This gives this error when run:
Fatal error: Cannot use object of type stdClass as array

How would I access the name of the first event?
Any suggestions?
  #6  
Old 04-17-2012, 09:06 AM
Tam's Loup Tam's Loup is offline
Junior Member
 
Join Date: Jan 2009
Posts: 21
Default

I have the answer, which I had thought I'd tried before. For those who are similarly stuck, the answer is...

$eventName = $eventResponse->Result->eventTypeItems->EventType[0]->name;
Post Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 03:24 PM.


BETFAIR® and the BETFAIR LOGO are registered trade marks of The Sporting Exchange Limited. Data on Betfair website(s) (including pricing data) is protected by © and database rights. It may not be used for any purpose without a licence. © The Sporting Exchange Limited. All rights reserved.