Search code examples
pythonsquarespacecurl

Squarespace returns no data using both curl and python


I am currently trying to build an integration between Quickbooks POS and squarespace. The official api documentation gives the following example:

curl "https://api.squarespace.com/1.0/commerce/products?cursor=abc" \
  -i \
  -H "Authorization: Bearer YOUR_API_KEY_OR_OAUTH_TOKEN" \
  -H "User-Agent: YOUR_CUSTOM_APP_DESCRIPTION"

which returns with error 52 (no data) from. My attempts to do this with python also returns no data.

import requests
print("start")
headers = {
    "Authorization": "API KEY",
    "User-Agent": "QBPOS integration"
}
square_api = requests.Session()
data = square_api.get('https://api.squarespace.com/1.0/commerce/products', headers=headers)
print(data)
print(data.text)

and python-squarespace returns an error stating that squarespace thinks this request is bogus.
All of the response codes are <403>.
What could cause it to this, how can I fix this?


Solution

  • Add Bearer before the API KEY!!

    import requests
    
    headers = {
        'Authorization': 'Bearer INSERT YOUR API KEY',
        'User-Agent': 'QBOS INTEGERATION',
        'Content-Type': 'application/json',
    }
    print("Hello World")
    response = requests.get('https://api.squarespace.com/1.0/authorization/website', headers=headers)
    print(response.text)
    

    The above code is to check your squarespace api key is valid or not. In Authorization you forgot the Bearer, and replace API KEY with your api key which square space provided. I guess that QUBOS integration is the key name of the square space API key.