West Wind Internet and Client Tools
Query parameters
Gravatar is a globally recognized avatar based on your email address. Query parameters
  ddprlewis
  All
  Jun 19, 2019 @ 10:05am

I'm working with the Paylocity API. I understand how to do "in: header" and "in: path" parameters, but how do you do "in: query" parameters?

Here's the documentation:

  '/v2/companies/{companyId}/employees/':
    get:
      description: Get All Employees API will return employee data currently available in Web Pay.
      operationId: Get all employees
      parameters:
        - description: Bearer + JWT
          in: header
          name: Authorization
          required: true
          type: string
        - description: Company Id
          in: path
          name: companyId
          required: true
          type: string
        - description: Number of records per page. Default value is 25.
          in: query
          name: pagesize
          required: false
          type: integer
        - description: 'Page number to retrieve; page numbers are 0-based (so to get the first page of results, pass pagenumber=0). Default value is 0.'
          in: query
          name: pagenumber
          required: false
          type: integer
        - description: Whether to include the total record count in the header's X-Pcty-Total-Count property. Default value is true.
          in: query
          name: includetotalcount
          required: false
          type: boolean

Here's some sample code:

lcScope = "WebLinkAPI"
lcApiVersion = "v2"
lcGrantType = "client_credentials"			
lcUserName = "???????"
lcPassword = "?????????"
lcCompanyID = "999999"
lcUrl = "https://api.paylocity.com/IdentityServer/connect/token"

lcEncodedData = "grant_type="+lcGrantType + "&client_id="+lcUserName + "&client_secret="+lcPassword + "&scope=" + lcScope
DO wwHttp
DO wwJsonSerializer
loHTTP=CREATEOBJECT("wwHttp")
loHttp.cContentType = "application/x-www-form-urlencoded"
loHttp.nHttpPostMode = 4
loHttp.AddPostKey(lcEncodedData)
loSer = CREATEOBJECT("wwJsonSerializer")
lcJsonResult = loHTTP.HTTPGet(lcURL)
loSer.FormattedOutput = .T.
loSer.DeserializeJson(lcJsonResult)
lcAccessToken = loResultObject.access_token
lcTokenType = loResultObject.token_type	&& lcTokenType is "Bearer"
loHTTP.AddHeader("Authorization: "+ lcTokenType + " " + lcAccessToken)

lcEmployeeURL = "https://api.paylocity.com/api/v2/companies/" + lcCompanyID + "/employees"

lcJsonEmpResult = loHTTP.HTTPGet(lcEmployeeURL)
loEmpResultObj = loSer.DeserializeJson(lcJsonEmpResult)

This all works, but is limited to 25 records per page and only the first page. I've tried adding properties, but that doesn't work, so I guess I just don't understand how to do "in: query" parameters and can't find any examples to borrow from.

Any insight on this would be helpful (and hopefully not just for me).

Gravatar is a globally recognized avatar based on your email address. re: Query parameters
  Rick Strahl
  ddprlewis
  Jun 19, 2019 @ 12:53pm

Query usually means query string, which is the key value list following the ? in the URL. IOW, you add that to the URL.

So to pass in the page:

lcEmployeeURL = "https://api.paylocity.com/api/v2/companies/" + lcCompanyID + "/employees"

*** Add query string
lcEmployeeUrl = lcEmployeeUrl + "?page=3&pageSize=10"

This makes sense based on the API - PageSize/Page number are 'adjustment' parameters to the actual request that modify the response on a higher level and it's common to pass those sorts of thing separately from the payload as it gets attached to lots of different requests in a API usually.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Query parameters
  ddprlewis
  Rick Strahl
  Jun 19, 2019 @ 01:16pm

Thanks. That worked like a charm.

That is what I was missing. I initially put it in as a "?" parameter, but then thought that it should be an ampersand instead of a question mark, so I changed it without testing, and obviously that didn't work.

Always appreciate when people are open to helping.

© 1996-2024