Forum Discussion
Error AccessForbinddenException to Refresh data
Hi emerson89 ,
Are you paginating it ? Try running it with 1 or 2 pages, just to check if you get this error.
- emerson896 years agoHelper I
Hi camargos88 ,
Yes, My query listaPedidosAquiles is paginate, but, alone, this work fine. I tested it by dividing the page quantity in half, and it worked fine. I tested it on 4 pages too, for example, and everything works normally. The problem occurs when I try to list all data. Any idea?
Thanks- camargos886 years agoCommunity Champion
I suspect the code tries to get more pages than the amount available.
How are you defining the amount of pages ?
- emerson896 years agoHelper I
Hi camargos88 ,
Really, your observation makes sense, however, when I run the query I use to separate the numbers (requests) to be used as a parameter for the second query, it works perfectly.
Here is my first query:
let ufnCallAPI = (nPage) => let result = Json.Document(Web.Contents("https://api.vhsys.com/", [RelativePath="v2/pedidos?offset=" & Number.ToText(nPage) & "&limit=250&status=Atendido", Headers=[#"access-token"="OCKNYbAMaDgLBZBSQPCOGPWOXGSbdO", #"secret-access-token"="xxxxxxxxx"]])) in result, tmpResult = ufnCallAPI(1), auxTotal1 = Record.ToTable(tmpResult), Value = auxTotal1{2}[Value], auxTotal2 = Value[total], totalItems = auxTotal2, pageRange = {0..Number.RoundUp(totalItems / 250)-1}, aux = List.Transform(pageRange, each ufnCallAPI(_*250)), aux2 = Table.FromList(aux, Splitter.SplitByNothing(), null, null, ExtraValues.Error), aux3 = Table.ExpandRecordColumn(aux2, "Column1", {"code", "status", "paging", "data"}, {"Column1.code", "Column1.status", "Column1.paging", "Column1.data"}), aux4 = Table.ExpandListColumn(aux3, "Column1.data"), aux5 = Table.RemoveColumns(aux4,{"Column1.code", "Column1.status", "Column1.paging"}), aux6 = Table.ExpandRecordColumn(aux5, "Column1.data", {"id_ped", "id_pedido", "id_cliente", "nome_cliente", "id_local_retirada", "id_local_cobranca", "vendedor_pedido", "vendedor_pedido_id", "listapreco_produtos", "valor_total_produtos", "desconto_pedido", "desconto_pedido_porc", "peso_total_nota", "peso_total_nota_liq", "frete_pedido", "valor_total_nota", "valor_baseICMS", "valor_ICMS", "valor_baseST", "valor_ST", "valor_IPI", "condicao_pagamento_id", "condicao_pagamento", "frete_por_pedido", "transportadora_pedido", "id_transportadora", "data_pedido", "prazo_entrega", "referencia_pedido", "obs_pedido", "obs_interno_pedido", "status_pedido", "contas_pedido", "comissao_pedido", "estoque_pedido", "ordemc_emitido", "data_cad_pedido", "data_mod_pedido", "id_aplicativo", "id_pedido_aplicativo", "lixeira"}, {"id_ped", "id_pedido", "id_cliente", "nome_cliente", "id_local_retirada", "id_local_cobranca", "vendedor_pedido", "vendedor_pedido_id", "listapreco_produtos", "valor_total_produtos", "desconto_pedido", "desconto_pedido_porc", "peso_total_nota", "peso_total_nota_liq", "frete_pedido", "valor_total_nota", "valor_baseICMS", "valor_ICMS", "valor_baseST", "valor_ST", "valor_IPI", "condicao_pagamento_id", "condicao_pagamento", "frete_por_pedido", "transportadora_pedido", "id_transportadora", "data_pedido", "prazo_entrega", "referencia_pedido", "obs_pedido", "obs_interno_pedido", "status_pedido", "contas_pedido", "comissao_pedido", "estoque_pedido", "ordemc_emitido", "data_cad_pedido", "data_mod_pedido", "id_aplicativo", "id_pedido_aplicativo", "lixeira"}), listPedidos = aux6[id_ped] in listPedidosThis code returns a list for me, for example:
List
1
2
3
48
56
88
89
100
The numbers above are numbers that I pass as a parameter in the query below calling query 1 (listaPedidos_Aquiles):
let ufnCallAPI = (numPedido) => let result = Json.Document(Web.Contents("https://api.vhsys.com/", [RelativePath="v2/pedidos/" & Number.ToText(numPedido) & "/produtos", Headers=[#"access-token"="OCKNYbAMaDgLBZBSQPCOGPWOXGSbdO", #"secret-access-token"="xxxxxxxx"]])) in result, pageRange = listaPedidos_Aquiles, pages = List.Transform(pageRange, each ufnCallAPI(_)), pages2 = Table.FromList(pages, Splitter.SplitByNothing(), null, null, ExtraValues.Error), pages3 = Table.ExpandRecordColumn(pages2, "Column1", {"code", "status", "data"}, {"code", "status", "data"}), pages4 = Table.ExpandListColumn(pages3, "data"), pages5 = Table.RemoveColumns(pages4,{"code", "status"}), #"data Expandido" = Table.ExpandRecordColumn(pages5, "data", {"id_ped_produto", "id_pedido", "id_produto", "desc_produto", "qtde_produto", "desconto_produto", "ipi_produto", "icms_produto", "valor_unit_produto", "valor_custo_produto", "valor_total_produto", "valor_desconto", "peso_produto", "peso_liq_produto", "info_adicional", "xPed_produto", "nItem_produto"}, {"id_ped_produto", "id_pedido", "id_produto", "desc_produto", "qtde_produto", "desconto_produto", "ipi_produto", "icms_produto", "valor_unit_produto", "valor_custo_produto", "valor_total_produto", "valor_desconto", "peso_produto", "peso_liq_produto", "info_adicional", "xPed_produto", "nItem_produto"}), #"Personalização Adicionada" = Table.AddColumn(#"data Expandido", "Empresa", each "Aquiles") in #"Personalização Adicionada"With order codes being sent by parameters, the API returns me the list of products for those orders.
When I test with little data, everything works. If I test with all the content (about 30 thousand lines), the system apparently starts to do the operation, I see in the message that everything is being generated correctly, but in the end, I get the error message.
There may actually be more items returning, than pages, but in this case, I am not able to find the error, because in this query2, I do not pass the page paging parameter as I send request by request (number), different from the query 1, that I return a quantity of items per page.
Thank you very much.