how to generate csv report and download using rest api
ravikiranmn
Posted 3 years ago·Last reply 1 year ago
8 comments
Vitor_Santos
·1 year ago
Just to add here. For some reason, I started to have this issue very recently.
Was using the SDK to make sure I'm up to date. Faced this issue, attempted the API endpoints directly (using v3), same thing. Thought on attempting API v2 & it works. I've a support case open for this, but just thought on adding this here for everyone that might be in the same situation.
Thank you!
mmatec01
·2 years ago
Wow,
I just stumbled across this thread…. Here, I thought I was being a good citizen, trying to align my scripts with official LM API v3 endpoint calls. So while the first part of getting report (/report/reports/{id}/executions) works fine, the second part of getting report - you know getting the actual data (CSV|HTML|PDF format) using the /report/reports/{REPORT_ID}/tasks/{TASK_ID} does not. Getting HTTP Status Code 404. Wasted an hour on that. It is broken. So yeah, back to fetching data via GET reportUrl. Which works fine.
LM User
·3 years ago
Postman is the right way to test it out. Did you follow the instructions in the link? Do that first and test that you have it working by doing a GET on /report/reports.
It’s fine that you redacted some information, but you didn’t redact your API key, which is the actual password to get into your API. You should be using the pre-request script in postman, all of which is explained in the postman setup instructions linked above.
ravikiranmn
OP3 years ago
Sorry its company’s job so hide the url
Stuart, how can we get report_id code to get reports
I am using Postman for testing purpose is there any other tool to test
Thank You Stuart for time and Support
LM User
·3 years ago
Looks like you’re not using Postman with variables. Your content-type is bad and you’re missing some stuff. Does postman work for any requests? Make sure your postman is working right.
Also, it looks like you have redacted some information, but you didn’t redact your API key.
I am getting 404 error please refer the attachment.
LM User
·3 years ago
You can use GET /report/links/{reportid} to get the list of links to the data. (warning, this endpoint is technically unsupported because LM decided it should be undocumented)
You’re supposed to be able to POST to /report/reports/{reportid}/executions to get it to generate the report immediately. The response should have the result url in it. However, in my testing the report url was always null because the report was not done generating by the time the API sent the response. Also, with this request, you have to pass in an email address that you want to send the report to. Once the task is finished, even if you get a null value in the API response, you will get the email with the link to the report.
So you should be able to
POST to /report/reports/{reportid}/executions with a bogus email (or your own) to start generating the report.
You probably want to wait a few seconds (maybe 30, maybe longer depending on the size of the report).
Then you should be able to GET at /report/links/{reportid} and get the last item in the list `$.items[-1:].reportUrl`. Then it would be a get at that URL. Be careful, it looks like there are extra spaces around the reportUrl, so use a .trim() method to clean it up before trying to fetch the CSV data itself.
Before you start, you could do the GET on /report/links/{reportid} first to get the id of the last report data. That would let you do repeated GETs at /report/links/{reportid} after doing your post and check if the new data is present by looking for a new ID after the known ID. That would let you wait a minimal amount of time before fetching the data again.
Vitor_Santos
·1 year agoJust to add here. For some reason, I started to have this issue very recently.
Was using the SDK to make sure I'm up to date. Faced this issue, attempted the API endpoints directly (using v3), same thing. Thought on attempting API v2 & it works. I've a support case open for this, but just thought on adding this here for everyone that might be in the same situation.
Thank you!
mmatec01
·2 years agoWow,
I just stumbled across this thread…. Here, I thought I was being a good citizen, trying to align my scripts with official LM API v3 endpoint calls. So while the first part of getting report (/report/reports/{id}/executions) works fine, the second part of getting report - you know getting the actual data (CSV|HTML|PDF format) using the /report/reports/{REPORT_ID}/tasks/{TASK_ID} does not. Getting HTTP Status Code 404. Wasted an hour on that. It is broken. So yeah, back to fetching data via GET reportUrl. Which works fine.
LM User
·3 years agoPostman is the right way to test it out. Did you follow the instructions in the link? Do that first and test that you have it working by doing a GET on /report/reports.
It’s fine that you redacted some information, but you didn’t redact your API key, which is the actual password to get into your API. You should be using the pre-request script in postman, all of which is explained in the postman setup instructions linked above.
ravikiranmn
OP3 years agoSorry its company’s job so hide the url
Stuart, how can we get report_id code to get reports
I am using Postman for testing purpose is there any other tool to test
Thank You Stuart for time and Support
LM User
·3 years agoLooks like you’re not using Postman with variables. Your content-type is bad and you’re missing some stuff. Does postman work for any requests? Make sure your postman is working right.
Also, it looks like you have redacted some information, but you didn’t redact your API key.
ravikiranmn
OP3 years agoThank You
Stuart Weenig for swift reply.
I am getting 404 error please refer the attachment.
LM User
·3 years agoYou can use GET /report/links/{reportid} to get the list of links to the data. (warning, this endpoint is technically unsupported because LM decided it should be undocumented)
You’re supposed to be able to POST to /report/reports/{reportid}/executions to get it to generate the report immediately. The response should have the result url in it. However, in my testing the report url was always null because the report was not done generating by the time the API sent the response. Also, with this request, you have to pass in an email address that you want to send the report to. Once the task is finished, even if you get a null value in the API response, you will get the email with the link to the report.
So you should be able to
Before you start, you could do the GET on /report/links/{reportid} first to get the id of the last report data. That would let you do repeated GETs at /report/links/{reportid} after doing your post and check if the new data is present by looking for a new ID after the known ID. That would let you wait a minimal amount of time before fetching the data again.