CMDBuild Forum

Re: Filter using REST API Returns everything

Please help with the correct way to filter via REST API - All the below options return everything...

cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"

#data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"CODE\",\"operator\":\"EQUALS\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"

data = '{"CQL":"from AWSServer WHERE Description CONTAINS \'linux\'"}'

#data = "{filter: '{\"cql\": \"from AWSServer where InstanceID EQUALS \'i-049347a98af506541\'\"}'}"

#data = "{filter: {'CODE': 'FCP-AL-WEB-RN03'}}"

headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }

r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)

pprint (r.json())

 
To filter cards by attribute value use:
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
 
To filter cards by using CQL filter use:
data = "{filter: '{\"CQL\": \"from AWSServer where Description CONTAINS \'linux\'\"}'}"
data = "{filter: '{\"CQL\": \"from AWSServer where Id in (/(select id from my_stored_procedure() )/)\"}'}"
 
CMDBuild Team
 
Previously Grant wrote:

Please help with the correct way to filter via REST API - All the below options return everything...

cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"

#data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"CODE\",\"operator\":\"EQUALS\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"

data = '{"CQL":"from AWSServer WHERE Description CONTAINS \'linux\'"}'

#data = "{filter: '{\"cql\": \"from AWSServer where InstanceID EQUALS \'i-049347a98af506541\'\"}'}"

#data = "{filter: {'CODE': 'FCP-AL-WEB-RN03'}}"

headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }

r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)

pprint (r.json())

 

 

Thank you for the quick reply. All of these options are still returning everything. Is the URL correct?
 
cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
pprint (r.json())
 
(This returns all AWSServer cards and not the single one I expect)
 
>>
 
Previously Tecnoteca wrote:
To filter cards by attribute value use:
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
 
To filter cards by using CQL filter use:
data = "{filter: '{\"CQL\": \"from AWSServer where Description CONTAINS \'linux\'\"}'}"
data = "{filter: '{\"CQL\": \"from AWSServer where Id in (/(select id from my_stored_procedure() )/)\"}'}"
 
CMDBuild Team
 
Previously Grant wrote:

Please help with the correct way to filter via REST API - All the below options return everything...

cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"

#data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"CODE\",\"operator\":\"EQUALS\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"

data = '{"CQL":"from AWSServer WHERE Description CONTAINS \'linux\'"}'

#data = "{filter: '{\"cql\": \"from AWSServer where InstanceID EQUALS \'i-049347a98af506541\'\"}'}"

#data = "{filter: {'CODE': 'FCP-AL-WEB-RN03'}}"

headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }

r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)

pprint (r.json())

 

 

 

The URL seems correct.
Which programming language are you using?
Try to remove double quotes before and after filter parenthesis:
data = {filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
 
CMDBuild Team
 
Previously Grant wrote:
Thank you for the quick reply. All of these options are still returning everything. Is the URL correct?
 
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
pprint (r.json())
 
(This returns all AWSServer cards and not the single one I expect)
 
>>
 
Previously Tecnoteca wrote:
To filter cards by attribute value use:
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
 
To filter cards by using CQL filter use:
data = "{filter: '{\"CQL\": \"from AWSServer where Description CONTAINS \'linux\'\"}'}"
data = "{filter: '{\"CQL\": \"from AWSServer where Id in (/(select id from my_stored_procedure() )/)\"}'}"
 
CMDBuild Team
 
Previously Grant wrote:

Please help with the correct way to filter via REST API - All the below options return everything...

cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"

#data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"CODE\",\"operator\":\"EQUALS\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"

data = '{"CQL":"from AWSServer WHERE Description CONTAINS \'linux\'"}'

#data = "{filter: '{\"cql\": \"from AWSServer where InstanceID EQUALS \'i-049347a98af506541\'\"}'}"

#data = "{filter: {'CODE': 'FCP-AL-WEB-RN03'}}"

headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }

r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)

pprint (r.json())

 

 

 

 

I'm using python. When removing the quotes I get the following error:
Traceback (most recent call last):
  File "test.py", line 154, in <module>
    r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
  File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
TypeError: keys must be a string
 
With quotes, everything is returned.
 
 
Previously Tecnoteca wrote:
The URL seems correct.
Which programming language are you using?
Try to remove double quotes before and after filter parenthesis:
data = {filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
 
CMDBuild Team
 
Previously Grant wrote:
Thank you for the quick reply. All of these options are still returning everything. Is the URL correct?
 
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
pprint (r.json())
 
(This returns all AWSServer cards and not the single one I expect)
 
>>
 
Previously Tecnoteca wrote:
To filter cards by attribute value use:
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
 
To filter cards by using CQL filter use:
data = "{filter: '{\"CQL\": \"from AWSServer where Description CONTAINS \'linux\'\"}'}"
data = "{filter: '{\"CQL\": \"from AWSServer where Id in (/(select id from my_stored_procedure() )/)\"}'}"
 
CMDBuild Team
 
Previously Grant wrote:

Please help with the correct way to filter via REST API - All the below options return everything...

cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"

#data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"CODE\",\"operator\":\"EQUALS\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"

data = '{"CQL":"from AWSServer WHERE Description CONTAINS \'linux\'"}'

#data = "{filter: '{\"cql\": \"from AWSServer where InstanceID EQUALS \'i-049347a98af506541\'\"}'}"

#data = "{filter: {'CODE': 'FCP-AL-WEB-RN03'}}"

headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }

r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)

pprint (r.json())

 

 

 

 

 

I'm using python. Removing the quotes gives me the following error:
Traceback (most recent call last):
  File "test.py", line 154, in <module>
    r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
  File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
TypeError: keys must be a string
 
- with the quotes, everything is returned
 
 
 
Previously Tecnoteca wrote:
The URL seems correct.
Which programming language are you using?
Try to remove double quotes before and after filter parenthesis:
data = {filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
 
CMDBuild Team
 
Previously Grant wrote:
Thank you for the quick reply. All of these options are still returning everything. Is the URL correct?
 
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
pprint (r.json())
 
(This returns all AWSServer cards and not the single one I expect)
 
>>
 
Previously Tecnoteca wrote:
To filter cards by attribute value use:
data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"
 
To filter cards by using CQL filter use:
data = "{filter: '{\"CQL\": \"from AWSServer where Description CONTAINS \'linux\'\"}'}"
data = "{filter: '{\"CQL\": \"from AWSServer where Id in (/(select id from my_stored_procedure() )/)\"}'}"
 
CMDBuild Team
 
Previously Grant wrote:

Please help with the correct way to filter via REST API - All the below options return everything...

cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"

#data = "{filter: '{\"attribute\":{\"simple\":{\"attribute\":\"CODE\",\"operator\":\"EQUALS\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}"

data = '{"CQL":"from AWSServer WHERE Description CONTAINS \'linux\'"}'

#data = "{filter: '{\"cql\": \"from AWSServer where InstanceID EQUALS \'i-049347a98af506541\'\"}'}"

#data = "{filter: {'CODE': 'FCP-AL-WEB-RN03'}}"

headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }

r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)

pprint (r.json())

 

 

 

 

 

I’m using python

 
Removing the quotes does not work - I get this error:
Traceback (most recent call last):
  File "test.py", line 154, in <module>
    r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
  File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
TypeError: keys must be a string
 
yet with the quotes, everything is returned
 
This is a python issue. In dictionaries, keys must be within quotes:
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
CMDBuild Team

Previously Grant wrote:

I'm using python
Removing the quotes does not work - I get this error:
Traceback (most recent call last):
File "test.py", line 154, in <module>
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
TypeError: keys must be a string
yet with the quotes, everything is returned
Thank you for your suggestions and assistance. 
 
I tried exactly that and still it returns everything. I include my entire script below - But I don't think I'm missing anything. This seems to be the case for other cards too, not just this one. 
 
 
#!/usr/bin/python
 
import requests, json, pprint
import os,sys
from pprint import pprint
#from prettytable import PrettyTable
from requests.auth import HTTPDigestAuth
import logging
 
 
print "***************************************************************"
print "*** Login and get authentication token "
print "***************************************************************"
 
cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/sessions/"
data = {'username': 'admin', 'password': 'password'}
headers = {'Content-type': 'application/json', 'Accept': '*/*'}
r = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)
 
print r.json()
r1=r.json()
sessionid=r1["data"]["_id"]
print "***************************************************************"
print " Authentication token is : " + sessionid
print "***************************************************************"
 
 
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
 
 
 
 
Previously Tecnoteca wrote:
This is a python issue. In dictionaries, keys must be within quotes:
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
 
CMDBuild Team
 

Previously Grant wrote:

I'm using python
 
Removing the quotes does not work - I get this error:
Traceback (most recent call last):
File "test.py", line 154, in <module>
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
TypeError: keys must be a string
 
yet with the quotes, everything is returned
 

 

Thanks again for your help :-)
 
I have tried exactly that and it still returns everything. This is still returns everything. Even other cards are the same.
 
This is so frustrating - IS there a curl example I could try rather. I'll use any programming language but surely this should work in python.
 
This is a test script:
 
#!/usr/bin/python
 
import requests, json, pprint
import os,sys
from pprint import pprint
#from prettytable import PrettyTable
from requests.auth import HTTPDigestAuth
import logging
 
 
print "***************************************************************"
print "*** Login and get authentication token "
print "***************************************************************"
 
cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/sessions/"
data = {'username': 'admin', 'password': 'password'}
headers = {'Content-type': 'application/json', 'Accept': '*/*'}
r = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)
 
print r.json()
r1=r.json()
sessionid=r1["data"]["_id"]
print "***************************************************************"
print " Authentication token is : " + sessionid
print "***************************************************************"
 
 
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
pprint (r.json())
 
 
  
Previously Tecnoteca wrote:
This is a python issue. In dictionaries, keys must be within quotes:
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
 
CMDBuild Team
 

Previously Grant wrote:

I'm using python
 
Removing the quotes does not work - I get this error:
Traceback (most recent call last):
File "test.py", line 154, in <module>
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
TypeError: keys must be a string
 
yet with the quotes, everything is returned
 

 

The results are not filtered because there are some issues in your Python code. You can find below a working python code and a cURL request based on CMDBuild READY2USE data model.
 
--- Python ---
#!/usr/bin/python
 
import requests, json, pprint
import os,sys
from pprint import pprint
from requests.auth import HTTPDigestAuth
import logging
 
print "***************************************************************"
print "*** Login and get authentication token "
print "***************************************************************"
 
cmdbuild_url = "http://localhost:8080/cmdbuild/services/rest/v2/sessions/"
headers = {'Content-type': 'application/json', 'Accept': '*/*'}
data = {'username': 'username', 'password': 'password'}
r = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)
 
print r.json()
r1=r.json()
sessionid=r1["data"]["_id"]
print "***************************************************************"
print " Authentication token is : " + sessionid
print "***************************************************************"
 
cmdbuild_url = "http://localhost:8080/cmdbuild/services/rest/v2/classes/Employee/cards/"
headers = {'Content-type': 'application/json', 'CMDBuild-Authorization': sessionid }
data = {'filter': json.dumps({"attribute":{"simple":{"attribute":"Code","operator":"equal","value":["a.anderson"]}}})}
r = requests.get(cmdbuild_url, params=data, headers=headers)
pprint (r.json())
 
--- cURL ---
curl -X GET \
  'http://localhost:8080/cmdbuild/services/rest/v2/classes/Employee/cards/?filter=%7B%22attribute%22%3A%20%7B%22simple%22%3A%20%7B%22operator%22%3A%20%22equal%22%2C%20%22attribute%22%3A%20%22Code%22%2C%20%22value%22%3A%20%5B%22a.anderson%22%5D%7D%7D%7D' \
  -H 'cmdbuild-authorization: 9mqkdvggravud3p9oisbhj8b5m' \
  -H 'cmdbuild-localization: en' \
  -H 'cmdbuild-localized: true' \
  -H 'content-type: application/json'
 
 
Previously Grant wrote:
Thanks again for your help :-)
 
I have tried exactly that and it still returns everything. This is still returns everything. Even other cards are the same.
 
This is so frustrating - IS there a curl example I could try rather. I'll use any programming language but surely this should work in python.
 
This is a test script:
 
#!/usr/bin/python
 
import requests, json, pprint
import os,sys
from pprint import pprint
#from prettytable import PrettyTable
from requests.auth import HTTPDigestAuth
import logging
 
 
print "***************************************************************"
print "*** Login and get authentication token "
print "***************************************************************"
 
cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/sessions/"
data = {'username': 'admin', 'password': 'password'}
headers = {'Content-type': 'application/json', 'Accept': '*/*'}
r = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)
 
print r.json()
r1=r.json()
sessionid=r1["data"]["_id"]
print "***************************************************************"
print " Authentication token is : " + sessionid
print "***************************************************************"
 
 
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
cmdbuild_url = "http://172.29.126.125:8080/cmdbuild/services/rest/v2/classes/AWSServer/cards"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
pprint (r.json())
 
 
  
Previously Tecnoteca wrote:
This is a python issue. In dictionaries, keys must be within quotes:
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
 
CMDBuild Team
 

Previously Grant wrote:

I'm using python
 
Removing the quotes does not work - I get this error:
Traceback (most recent call last):
File "test.py", line 154, in <module>
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
TypeError: keys must be a string
 
yet with the quotes, everything is returned
 

 

 

Thank you so much for your assistance
 
The issue was params=data as parameter - this small thing - argh!
 
You have been a great help - I knew it would be something small Many thanks  :-)
 
 
 
Previously Tecnoteca wrote:
The results are not filtered because there are some issues in your Python code. You can find below a working python code and a cURL request based on CMDBuild READY2USE data model.
 
--- Python ---
#!/usr/bin/python
 
import requests, json, pprint
import os,sys
from pprint import pprint
from requests.auth import HTTPDigestAuth
import logging
 
print "***************************************************************"
print "*** Login and get authentication token "
print "***************************************************************"
 
headers = {'Content-type': 'application/json', 'Accept': '*/*'}
data = {'username': 'username', 'password': 'password'}
r = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)
 
print r.json()
r1=r.json()
sessionid=r1["data"]["_id"]
print "***************************************************************"
print " Authentication token is : " + sessionid
print "***************************************************************"
 
headers = {'Content-type': 'application/json', 'CMDBuild-Authorization': sessionid }
data = {'filter': json.dumps({"attribute":{"simple":{"attribute":"Code","operator":"equal","value":["a.anderson"]}}})}
r = requests.get(cmdbuild_url, params=data, headers=headers)
pprint (r.json())
 
--- cURL ---
curl -X GET \
  -H 'cmdbuild-authorization: 9mqkdvggravud3p9oisbhj8b5m' \
  -H 'cmdbuild-localization: en' \
  -H 'cmdbuild-localized: true' \
  -H 'content-type: application/json'
 
 
Previously Grant wrote:
Thanks again for your help :-)
 
I have tried exactly that and it still returns everything. This is still returns everything. Even other cards are the same.
 
This is so frustrating - IS there a curl example I could try rather. I'll use any programming language but surely this should work in python.
 
This is a test script:
 
#!/usr/bin/python
 
import requests, json, pprint
import os,sys
from pprint import pprint
#from prettytable import PrettyTable
from requests.auth import HTTPDigestAuth
import logging
 
 
print "***************************************************************"
print "*** Login and get authentication token "
print "***************************************************************"
 
data = {'username': 'admin', 'password': 'password'}
headers = {'Content-type': 'application/json', 'Accept': '*/*'}
r = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)
 
print r.json()
r1=r.json()
sessionid=r1["data"]["_id"]
print "***************************************************************"
print " Authentication token is : " + sessionid
print "***************************************************************"
 
 
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
pprint (r.json())
 
 
  
Previously Tecnoteca wrote:
This is a python issue. In dictionaries, keys must be within quotes:
data = {'filter': '{\"attribute\":{\"simple\":{\"attribute\":\"Code\",\"operator\":\"equal\",\"value\":[\"FCP-AL-WEB-RN03\"]}}}'}
 
CMDBuild Team
 

Previously Grant wrote:

I'm using python
 
Removing the quotes does not work - I get this error:
Traceback (most recent call last):
File "test.py", line 154, in <module>
r = requests.get(cmdbuild_url, data=json.dumps(data), headers=headers)
File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
TypeError: keys must be a string
 
yet with the quotes, everything is returned