Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
let
    /*****************************
    * Variables
    *****************************/
    url = "https://www.wordbee-translator.com/api/auth/token",
    urlJobsList = "https://www.wordbee-translator.com/api/jobs/list",
    maxItems = 200,
    apiKey = "XXXX-XXXX-XXXX-XXXX-XXXX",
    accountid = "XXXX",

    /*****************************
    * Functions
    *****************************/
    GetToken = Web.Contents(url, [Headers = [ #"Accept"="application/json",    
				              #"Content-Type"="application/json;charset=UTF-8"],
                                  Content = Text.ToBinary("{'accountid': '" & accountid &"', 'key': '" & apiKey & "'}")]),
								  
    AccessToken = Json.Document(GetToken),
    GetBody = (page, take) => "{'query': '{created}.Matches(""-2m"", "">="")', 'take': '" & Text.From(take) & "','skip': '" & Text.From(page * take) & "'}",
    GetPartial = (page, take) => 
		let body = GetBody(page, take),
  		Value = Json.Document(Web.Contents(urlJobsList, [ Headers=[ #"Accept"="application/json",    
                                                                            #"Content-Type"="application/json;charset=UTF-8",
                                                                            #"X-Auth-AccountId"= accountid,
                                                                            #"X-Auth-Token"= AccessToken ],
					    			 Content = Text.ToBinary(body) ]))
		in Value,
    GetRange = (page) => GetPartial(page, maxItems),
	
    /*****************************
    * Results
    *****************************/
    Total = GetPartial(0, 0)[total],
    PageCount   = Number.RoundUp(Total / maxItems),
    PageIndices = { 0 .. PageCount - 1 },
    Pages       = List.Transform(PageIndices, each GetRange(_)[rows]),
    Entities    = List.Union(Pages),
    Source       = Table.FromList(Entities, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
	Source





...