i am trying to pull data by referencing this guide. I'm a little new. can i just pull data with api key and url. Because i have only api key and url. I don't have any of the other parameters. Here are the ways i tried:
import urllib.parse
import urllib.request
url = "https://commerce.campaignmonitor.com/api/v1/abandoned-carts/campaigns"
header={"x-api-key" : 'my_api_key'}
post_param = urllib.parse.urlencode({
'user' : 'i_dont_know',
'status-update' : 'i_dont_know'
}).encode('UTF-8')
req = urllib.request.Request(url, post_param, header)
response = urllib.request.urlopen(req)
and this:
from requests.auth import HTTPBasicAuth
import requests
import urllib
url ="https://commerce.campaignmonitor.com/api/v1/abandoned-carts/campaigns"
headers = {"Accept": "application/json"}
auth = HTTPBasicAuth('my_api_key', 'i_dont_know')
req = requests.get(url, headers=headers , auth=auth)
response = urllib.request.urlopen(req)
but i have error:
AttributeError: 'Response' object has no attribute 'type'
in other methods, I get 401 error
python-requestsalone can do this for you (no need forurllib). You have theAPI keyso you shouldn't use theHTTPBasicAuththis should work for you: