In the end I want to "scrape" the following webpage when doing an advanced search for last two days.
https://launchstudio.bluetooth.com/Listings/Search
Results seems to be generated by a javascript that calls a API
bt.apiUrl = 'https://platformapi.bluetooth.com/';
$.ajax({
method: 'post',
contentType: "application/json; charset=utf-8",
dataType: "json",
url: bt.apiUrl +'api/platform/Listings/Search',
data: JSON.stringify(this.searchCriteria),
success: function (data) {
if (data.length) {
var listings = data
console.log('listing count: ' + listings.length);
this.listings = listings;
}
}.bind(this)
Found the following API documentation:
https://platformapi.bluetooth.com/Help/Api/POST-api-Platform-Listings-Search
However, my simple script returns 404
import requests
import json
payload ={
'UserId': '',
'MemberId': '',
'SearchString': '',
'SearchQualificationsAndDesigns': 1,
'SearchDeclarationOnly': 1,
'SearchEndProductList': 1,
'SearchPRDProductList': 1,
'SearchMyCompany': 1,
'BQAApprovalStatusId': 9,
'BQALockStatusId': 10,
'ProductTypeId': 1,
'SpecName': 1,
'ListingDateEarliest': "2017-11-17T09:43:09.2031162-06:00",
'ListingDateLatest': "2017-11-18T09:43:09.2031162-06:00",
'Layers': [],
'MaxResults': 11,
'IncludeTestData': 1
}
url = 'https://platformapi.bluetooth.com/api/Platform/Listings/Search'
headers = {'Content-type': 'application/json', 'Accept': 'text/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)
print (r.status_code)
Anyone can see why? Using Python 3.5 btw.
import requests
import json
payload = {
"searchString":"bluetooth",
"searchQualificationsAndDesigns":True,
"searchDeclarationOnly":True,
"searchEndProductList":False,
"searchPRDProductList":True,
"searchMyCompany":False,
"productTypeId":0,
"specName":0,
"bqaApprovalStatusId":-1,
"bqaLockStatusId":-1,
"listingDateEarliest":"",
"listingDateLatest":"",
"userId":0,
"memberId":None,
"layers":[],
"maxResults":5000
}
url = 'https://platformapi.bluetooth.com/api/Platform/Listings/Search'
headers = {'Content-type': 'application/json; charset=utf-8', 'Accept': 'text/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)
print (r.status_code)
#print r.json()
Result:
200
Related
My audio for podcast and art for it on google drive, in doc says to make like this, but it returns 400 error
import requests
podcast_file = "https://drive.google.com/file/d/1w0IDXVotyHKEGSbBWUxEoDvaJQRsWCJO"
headers = {
'Authorization': 'Token here my token',
'Content-Type': 'application/json',
}
new_episode = {
"title":"Too many or too few?",
"description":"",
"summary":"",
"artist":"Muffin Man",
"tags":"",
"duration":23462,
"guid":"Buzzsprout788880",
"episode_number":1,
"season_number":1,
"explicit":False,
"private":False,
"email_user_after_audio_processed": False,
"audio_url": podcast_file,
"artwork_url": "https://drive.google.com/file/d/1xoNKAbTYX8GjVg0ZB_ekFUl8ljQICMZv"
}
url = 'https://www.buzzsprout.com/api/episodes.json'
req = requests.post(url, data=new_episode, headers=headers)
print(req.text)
print(req.status_code)
I am requesting to mindbodyapi to get token with the following code using requests library
def get_staff_token(request):
URL = "https://api.mindbodyonline.com/public/v6/usertoken/issue"
payload = {
'Api-Key': API_KEY,
'SiteId': "1111111",
'Username': 'user#xyz.com',
'Password': 'xxxxxxxx',
}
r = requests.post(url=URL, params=payload)
print(r.text)
return HttpResponse('Done')
gives a response as follows
{"Error":{"Message":"Missing API key","Code":"DeniedAccess"}}
But if I request the following way it works, anybody could tell me, what I am doing wrong on the above code.
conn = http.client.HTTPSConnection("api.mindbodyonline.com")
payload = "{\r\n\t\"Username\": \"username\",\r\n\t\"Password\": \"xxxxx\"\r\n}"
headers = {
'Content-Type': "application/json",
'Api-Key': API_KEY,
'SiteId': site_id,
}
conn.request("POST", "/public/v6/usertoken/issue", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
In the second one, you are passing the API Key in headers and the credentials in the body of the request. In the first, you are sending both the API Key and credentials together in the query string, not the request body. Refer to requests.request() docs
Just use two dictionaries like in your second code and the correct keywords, I think it should work:
def get_staff_token(request):
URL = "https://api.mindbodyonline.com/public/v6/usertoken/issue"
payload = {
'Username': 'user#xyz.com',
'Password': 'xxxxxxxx',
}
headers = {
'Content-Type': "application/json",
'Api-Key': API_KEY,
'SiteId': "1111111",
}
r = requests.post(url=URL, data=payload, headers=headers)
print(r.text)
return HttpResponse('Done')
I want to have a python request and add pagination, but for some reason it does not work,
this is my request. Does someone know how to add 'paging': '{"page":0,"size":100}' corretly? The following isn't working?
url = self.get_url_for_endpoint(Constants.PATH_STATISTICS_CUSTOMERS)
payload = {}
params = {
'paging': '{"page":0,"size":100}'
}
headers = {
'Authorization': 'Bearer ' + self.access_token,
'Cookie': 'JSESSIONID=AB52DV8260C*****************',
'Content-Type': 'application/json',
}
r = requests.request("GET", url, headers=headers, data=payload, params=params)
This is working though via postman:
url + ?paging=%7B%22page%22:0,%22size%22:400%7D
So the endpoint has pagination!
I wouldn't recommend using an object as your paging value in the params, instead break down your page and size into individual parameters, like ?page=0&size=100.
But if you want to use an object, your params should be like this:
params = {
"paging": {"page":0,"size":100}
}
I am sending a JSON post request to a URL with headers and para:
headers = {
'channel':'mobiApp',
'Content-Type': 'application/json; charset=UTF-8',
'Content-Length': '939',
'Cookie': 'xyzxcasd',
'User-Agent': 'okhttp/3.8.0'
}
url = 'https://api.xyz.com/account.jsp'
data = {'act':'login','class':'profile','prftcf':code1,'p':password1,'u':username1,'ver':'0.9.1'}
content = json.dumps(data)
print ("")
print (content)
print ("")
r = requests.post(url,headers=headers,data=content,allow_redirects=True)
z = r.text
(above is the request I am sending)
I am getting this as response:
{
"s": 0,
"err": "",
"errCode": "",
"status": "",
"ccnt": 1,
"em": "blueyes81382#yahoo.com",
"pid": "2436999645",
"bvUserToken": "ee936b7065353389878696fc7cc4d71a646174653d3230313730393137267573657269643d32343336393939363435"
}
What I want to do is redirect after this post request (if bvUSertoken exists) to some URL, i.e.: https://api.xyz.com/acount/summary, and print the response.
okay so i found a solution to this
p['Set-cookie'] parse cookie from previous response header
cookies = (p['Set-Cookie'])
headers1 = {
'channel':'mobiApp',
'Content-Type': 'application/json; charset=UTF-8',
'Cookie' : cookies,
'User-Agent': 'okhttp/3.8.0'
}
url = 'your redirect url'
urlx = url
parsing = requests.get(urlx,headers=headers1)
I want to update the title of a pull request and performing the below to achieve it :- (followed this doc https://developer.github.com/v3/pulls/#update-a-pull-request)
data = {"title": "New title"}
url='https://hostname/api/v3/repos/owner/repo/pulls/80'
token = 'my-token'
headers = {'Content-type': 'application/json', 'Accept': 'application/json', 'Authorization': 'token %s' % token}
resp = requests.patch(url, data=json.dumps(data), headers=headers)
print resp.json()
What am I missing ? Please help.
The following worked for me:
import requests
token = "my-token"
url = "https://api.github.com/repos/:owner/:repo/pulls/:number"
payload = {
"title": "New title"
}
r = requests.patch(url, auth=("username", token), json=payload)
print r.json()