Need help calling an API using JSON
I've been using CF inside the firewall for years; I've never really had to do API calls. That said, I have the below problem that I don't know how to solve and I'm hoping someone can help. I have searched this site and StackOverFlow and while I find suggestions, I can't find an answer.
Can someone help? I have been experimenting with CFHTTP but can't seem to figure it out. I'd provide a sample of what I'm doing, but I think I am so far off it won't help.Here is the information I received for this need:
This API allows external systems to request a report and provides an endpoint to check for the status of the report's completion. Once completed, the contents of the report can be downloaded as a CSV file.
The flow for using the reports API is simple: send an HTTP POST request containing a JSON-formatted payload the metadata on what kind of report to run and what kinds of columns to include and what to filter by. If successful, the response will contain the URL to poll for the status of the report that will be generated. Poll this URL until it shows a completed status and a URL where the final CSV file is located.
You can make the HTTP request using any HTTP client you want, but the simplest would be to use the "curl" command. The curl request will look like this, substituting the underlined parts for the appropriate values:
curl -i -X POST --user "YOUR_USERNAME:YOUR_PASSWORD" \
https://myserver.com/api/reports/report_runs \
-H 'Content-Type: application/json' \
-d '{
...
}'Explanation: The -i flag will print the response header out, which will contain a header named Location to poll for the status of the report. The -X POST flag specifies the request method of POST which is necessary to append a payload. The --user "YOUR_USERNAME:YOUR_PASSWORD" flag specifies that the request will use basic authentication which will transmit the username and password, separated by a colon (:) character, in base 64 encoding. The -H "Content-Type: application/json" flag specifies that the payload is in JSON format, then the -d "{...}" flag specifies the actual payload. The payload is explained below. Finally, the URL is at the end of the command - ensure that the domain matches whatever domain you are using to access the application.
The payload is a JSON object structured as follows:
{
"report": "report_name",
"columns": [ "column_one", "column_two" ], "filters": [ { "column": "column_two", "operator": "=", "threshold": 5 } ]}
