Retrieve markets by event id

I’m new to APIs and need a little help with this error. I’m struggling to know how to format my code to obtain the markets of an event. The example event I’ve used is 41889540 (Man City vs Arsenal). I just want to retrieve the market IDs necessary to eventually place bets on this event.

I am using python with the requests module to make calls to the API.

Here’s my code (apologies in advance for any obvious errors):
event_id = 41889540
url = “https://api.smarkets.com/v3/{event_ids}/markets/
headers = {“Content-Type”: “application/json”}
data = {“event_ids”: event_id}
response = requests.get(url, headers=headers, params=data)
print(response)
print(response.json())

The responses I get:
<Response [404]>
{‘data’: {‘description’: ‘Nothing matches the given URI’}, ‘error_type’: ‘NOT_FOUND’}

Hey Clement. So a couple of issues here, you’re missing /events/ from your URL after /v3/ for starters, but also when you see {} in the URL you need to replace that with a value, in this case the event IDs you want to fetch the markets for. So rather than passing the event ID as a param, for your example try something like this:

import requests

event_id = 41889540
url = “https://api.smarkets.com/v3/events/{}/markets/".format(event_id)
headers = {“Content-Type”: “application/json”}
response = requests.get(url, headers=headers)

If you’ve any further issues just give us a shout.

1 Like

Hi, some follow up questions to the original.

How do I get more than one result back from https://api.smarkets.com/v3/events/{event_ids}/markets/ ?

What I can see from https://docs.smarkets.com/ is:
event_ids, array[integer]
and
Event IDs to filter by
maxItems:50

I interpret this (by array[integer]) that it is at least possible to get several ids back. In what format do I need to pass in the array of integers? I have tried several ways but I’m not getting anything back (404 error). I’m using python for coding.

One last question, maxItems:50 what does this mean, can I only send in 50 event_ids in the array at one time? What is then the recommended way to get data for more than 50 event_ids? Loop and append data?

Thank you,
Best regards
Daniel

Hi Daniel,

You can use the get_related_markets method from our sample code https://github.com/smarkets/smk_trading_bot/blob/master/client.py

and, for example, pass in:

events = [{"id":'41895874'}, {"id":'41895873'}]

50 is the maximum number of event_ids you can have in your request. You’d need to make another request to get information on additional events.

Hi Eddie,

Big thanks for this. I missed it completely.

Best regards
Daniel