Discussion Forums

Parameters for List Request

 
Apprentice
8 posts

Hello,

I am trying to supply some parameters for at GET request on /contacts.

The server seems to be ignoring my attempts to limit the results!

I have attached a small python script that I think should only return 2 results…

Do you need to supply all the parameters in the request?

Do you need to have an ‘outer’ request dictionary with JSON encoding?  ie.

{‘request’:{‘limit’:2}}

Thanks.

File Attachments
contacts.txt  (File Size: 1KB - Downloads: 284)
Avatar
Administrator
3952 posts

Greetings Scott,

By default all records will be returned so you actually don’t need to provide any parameters to the list to return data.  For example, you can use https://secure.solve360.com/contacts or limit by providing the one parameter https://secure.solve360.com/contacts?limit=2

You don’t need a ‘outer’ request dictionary when using JSON encoding.  If content-type is application/json your request body should be like this: {‘limit’:2}  If using application/xml there should be a wrapping ‘outer’ request node e.g. <request></request>

We tried a representative test using your example and were able to get the result we expected:

Request:

GET /contactsHTTP/1.1
Host
secure.solve360.com
Authorization
Basic cGluZ0Bub3JhZGEuY29tOkJjUzBFODk4RzVSYlg2bDAwY2YzUmV4ODU1YjBnYjI0TmVvYjBiUjk=
Content-Typeapplication/xml
Accept
application/json
Content
-Length273
Connection
close

<?xml version
="1.0" encoding="utf-8"?>
<request><layout>1</layout><searchmode></searchmode><searchvalue></searchvalue>
<
filtermode></filtermode><filtervalue></filtervalue><special></special><limit>2</limit>
<
start></start><sortfield></sortfield><sortdir></sortdir></request

Response (2 contacts):

{"141367":{"id":141367,"name":", ","parentid":138933,"flagged":false,"website":"","homephone":"","background":"",
"businessphonemain":"","businessfax":"","homeaddress":"","businessaddress":"","cellularphone":"",
"businessphonedirect":"","businessemail":"","lastname":"","firstname":",","personalemail":"test1@test.com",
"created":"2009-08-27T04:12:34+00:00","viewed":"2009-08-27T04:12:34+00:00","updated":"2009-08-27T23:52:45+00:00"},
"141330":{"id":141330,"name":",","parentid":138933,"flagged":false,"website":"","homephone":"","background":"",
"businessphonemain":"","businessfax":"","homeaddress":"","businessaddress":"","cellularphone":"",
"businessphonedirect":"","businessemail":"","lastname":"","firstname":",","personalemail":"test2@test.com",
"created":"2009-08-27T04:12:13+00:00","viewed":"2009-08-27T04:12:14+00:00","updated":"2009-08-27T23:52:26+00:00"},
"count":2359,"status":"success"

Does this help?

Apprentice
8 posts

Thanks for the additional information.  The code posted here now works as expected using json in both directions.

What is the preferred way of posting code to these forums?  Single and double quotes are transformed into the nicer looking but illegal left and right slated cousins, even inside < code > blocks…

#!/usr/bin/env python

import httplib
import string, base64, json

userid = ‘*‘
passwd = ‘*‘

headers = {‘Accept’: ‘application/json’, ‘Content-Type’: ‘application/json’}
headers[‘Authorization’] = ‘Basic ‘ + string.strip(base64.encodestring(userid + ‘:‘ + passwd))

connection = httplib.HTTPSConnection(“secure.solve360.com”)

parameters = {‘limit’:2}

connection.request(“GET”, “/companies”, json.dumps(parameters), headers)

response = connection.getresponse()
print response.status, response.reason

reply = json.loads(response.read())
print reply

Avatar
Administrator
3952 posts

The forums support the pMcode syntax so the code tags should be wrapped in square brackets.