I am trying to return a specific group by ID in GroupMe using Python. The official documentation states that, to get a specific group, you append the base URL with /groups/:id
and add the group ID number as a parameter (along with the access token). From the documentation, it says that the ID needs to be a string.
So, I am aware of the fact that the server is not receiving the correct form, but I don't know how to send the 'correct form,' whatever that may be.
As a note, I am running Python 3.10.
This is the code that I am using:
import requests
import json
parameter = {'id':'12345678'}
url_link = 'https://api.groupme.com/v3/groups/:id?token=token123455'
answer = requests.get(url_link, params=parameter)
print(answer.json())
However, every time I pass the parameter (both as a JSON or a query string), the API always returns with:
{"meta":{"code":400,"errors":["param is not a number"]}}
To further test it, I tried to use cURL:
url -X GET https://api.groupme.com/v3/groups/:id?token=token12345&id=12345678
Got the same error as above. I'm pretty stumped on what to do; any help?
This is my first post here (and my background isn't in computer science or software engineering) so I hope I have provided enough information.
That syntax :id
means a path parameter. You replace it with the actual value of group id
.
Also authentication documentation mentions two ways of passing the access token. The one employing headers should be the preferred one. Passing sensitive data in URLs is not a good idea.
Concerning these, retrieval of group information could be done so:
import requests
import json
url = f'https://api.groupme.com/v3/groups/{group_id_value}'
headers = {
'X-Access-Token': your_token_value,
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
print(response.json())