Solved

API call | exportPipeReport | Problems with download from Pipefy URL

  • 2 August 2022
  • 1 reply
  • 294 views

Userlevel 4

Hi Pipe Friends!

 

I’m building this code to make an external backup of specific pipes report. But i can’t download the report in the end. I receive this error message:

 

"https://url_returned_by_pipefy"
Ocorreu um erro: (<class 'urllib.error.URLError'>, URLError('unknown url type: "https'), <traceback object at 0x000001C6002DD680>)

I think that I wasn’t using the right method to parse into string the url_relatorio variable. I’m using Python 3

import requests
import json
import urllib
import sys
from urllib.request import urlopen

url = "https://api.pipefy.com/graphql"

payload_id_relatorio = {"query": "mutation {exportPipeReport(input: { pipeId:\"XXXX\", pipeReportId: \"XXXX\"}) {pipeReportExport {id}}}"}
headers = {
"Authorization": "Bearer XXXX",
"Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload_id_relatorio, headers=headers)
data = json.loads(response.text)
Id_relatorio = data['data']['exportPipeReport']['pipeReportExport']['id']

payload_obter_url_relatorio = {"query": "{pipeReportExport(id: "+ Id_relatorio + "){fileURL state startedAt requestedBy {id}}}"}
headers = {
"Authorization": "Bearer XXXX",
"Content-Type": "application/json"
}
response_obter_url_relatorio = requests.request("POST", url, json=payload_obter_url_relatorio, headers=headers)
data_relatorio = json.loads(response_obter_url_relatorio.text)
url_relatorio = json.dumps(data_relatorio['data']['pipeReportExport']['fileURL'])

print(url_relatorio)

try:
urllib.request.urlretrieve(url_relatorio, 'C://Users/user/Downloads/teste.xlsx')
print("Arquivo salvo! =)")

except:
erro = sys.exc_info()
print("Ocorreu um erro:", erro)

 

Could anyone give me some help in this case? Tks a lot!

 

Best regards!

icon

Best answer by Marcos Carvalho 8 August 2022, 21:20

View original

1 reply

Userlevel 6
Badge +6

hey @Diego Anselmo Saiotti 

your integration with Pipefy is working well. The issue is the urllib usage. 
 

HTTPS support is only available if Python was compiled with SSL support (through the ssl module).

Here some documentation that might help. 

https://docs.python.org/3/library/http.client.html

Some users faced the same issue here: 

https://stackoverflow.com/questions/28376506/urllib-https-request-urlopen-error-unknown-url-type-https

In this case you need to check your environment and make the proper configuration to manipulate HTTPS urls.

Hope it helps you. 

Reply