How can I run a JSON script into a requests.get to get out a table from Alloy?

47 views Asked by At

I am trying to send a json requests to alloy that runs a json code and outputs the data.

'''

aqs = {"aqs": {
    "type": "Join",
    "properties": {
        "attributes": [
            "attributes_itemsTitle",
            "attributes_itemsSubtitle"
        ],
        "collectionCode": [
            "Live"
        ],
        "dodiCode": "designs_nlpgPremises",
        "joinAttributes": []
    },
    "children": [
        {
            "type": "And",
            "children": [
                {
                    "type": "Equals",
                    "children": [
                        {
                            "type": "Attribute",
                            "properties": {
                                "attributeCode": "attributes_premisesPostcode"
                            }
                        },
                        {
                            "type": "String",
                            "properties": {
                                "value": [
                                    "BS5 6AP"
                                ]
                            }
                        }
                    ]
                }
            ]
        }
    ]
}}

   
    headers = { 'X-Authentication-Token' : token }
    urlBase = 'https://uk.alloyapp.io/api/'
    requestURL = urlBase + 'aqs/join?token=' + token
    response = requests.get(requestURL, headers = headers, data=json.dumps(aqs))
    print(response.text)

When I run this code I get this error

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
This distribution is not configured to allow the HTTP request method that was used for 
this request. The distribution supports only cachable requests.
We can't connect to the server for this app or website at this time. There might be too 
much traffic or a configuration error. Try again later, or contact the app or website 
owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to 
troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: txrBxRox0BvgpLAFSbqvBztjhYsUmUzWdjizayD20tinETqt85fG==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
1

There are 1 answers

0
Andrej Kesely On

According the API documentation (https://api.uk.alloyapp.io/swagger/ui/index.html?url=/swagger#/Aqs/Aqs_Join) you should use POST (not GET):

import requests

payload = {
    "aqs": {"type": "Query", "properties": {}, "children": ["string"]},
    "parameterValues": [{"name": "string", "value": {}}],
}

api_url = "https://api.uk.alloyapp.io/api/aqs/join"

headers = {"X-Authentication-Token": "<REDACTED>"}

data = requests.post(api_url, json=payload, headers=headers).json()
print(data)