Forum Discussion

mhilzendegen's avatar
mhilzendegen
Regular Visitor
3 years ago

error handling of 404

Hi,

 

Pipedrive sadly started permadeleting deals, so my loop through the deals to grab the products behind the deals now fails with a 404. I am really bad with "otherwise". Anyone see what I have to do??

 

Here is the code:

 

let
Source = Json.Document(Web.Contents("https://digainfo.pipedrive.com/v1/deals:(id)?api_token=xyz",[Query=[api_token="xyz", limit="1", start="0", get_summary="1", filter_id="305"]])),
#"Converted to Table Record" = Record.ToTable(Source),
Value = #"Converted to Table Record"{2}[Value],
summary = Value[summary],
total_records = summary[total_count],

 

Starts = List.Generate(()=>1, each _ < total_records, each _ + 1),
#"Converted to Table" = Table.FromList(Starts, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Json.Document(Web.Contents("https://digainfo.pipedrive.com/v1/deals/"&[Column1]&"/products:(id,deal_id,product_id,item_price,sum,currency,add_time,comments,name,quantity)?api_token=xyz",[Query=[api_token="xyz", limit="500", start="0"]]))),

 

---

 

i tried

 

#"Added Custom" = each Table.AddColumn(#"Changed Type", "Custom", each Json.Document(Web.Contents("https://digainfo.pipedrive.com/v1/deals/"&[Column1]&"/products:(id,deal_id,product_id,item_price,sum,currency,add_time,comments,name,quantity)?api_token=xyz",[Query=[api_token="xyz", limit="500", start="0"]]))) otherwise 0,

 

But that nets me a "not in dictionary"

 

Thanks y'all

 

2 Replies

  • Hi mhilzendegen ,

     

    The correct syntax is 'try...otherwise'. It looks like you are attempting to apply 'each...otherwise' syntax, which doesn't exist.

    I think you may be aiming for something like this:

    #"Added Custom" =
    Table.AddColumn(
        #"Changed Type",
        "Custom",
        each try
            Json.Document(Web.Contents("https://digainfo.pipedrive.com/v1/deals/"&[Column1]&"/products:(id,deal_id,product_id,item_price,sum,currency,add_time,comments,name,quantity)?api_token=xyz",[Query=[api_token="xyz", limit="500", start="0"]]))
        otherwise 0
    ),

     

    Pete

    • mhilzendegen's avatar
      mhilzendegen
      Regular Visitor

      Hi Pete, sorry, I tried that too. Also gives me the not in dictionary error

      Whatever that is.

       

      Error Message: The given key was not present in the dictionary.