Counter for Pagination

Viewed 27

I try to set up an API-Call and I need a specific header. I need a signature that will renew on every call including a offset. Thats what i have:

<#assign method = "GET">    
<#assign uri = "the_requestet_url?limit=30">    
<#assign body = "">    
<#assign timestamp = (.now?long / 1000)?split(".")[0]>    
<#assign gesamt>${method}${"\n"}${uri}${"\n"}${body}${"\n"}${timestamp}</#assign>    
<#assign secret ="here_is_a_secret_key">    
<#assign signature = hmacSHA256(gesamt, secret, "hex")!>

The call is:

Accept=application/json    
HM-Timestamp=${timestamp}    
HM-Signature=${signature}    
HM-Client=here_is_a_client_id

The Api delivers max 30 entrys back and after i need an offset in

<#assign uri = "the_requestet_url?limit=30">

that counts up with every call and starts with the next 30 entrys.

The key has to be renewed every call. I think i need a counter in here but i didn´t get it to work

I will do the pagination that looks something like this:

<#assign row = target.addRow()>    
  
<#assign numRows = 0 />    
  
<#list json as p>    
 <#assign row = target.addRow()>    
    ${addColumns(row, p['product'])}    
    <#assign numRows = numRows + 1 />    
</#list>    
  
  
<#if (numRows > 0 && callcounter < callLimit)>    
    <#assign nextPageNumber = (callcounter + 1)>    
    ${nextUrl(initialUrl+"&page="+nextPageNumber)}    
</#if>    

Any idea how i can get the counter to work?

Thanks in advance and BR Enrico

0 Answers
Related