Hi irach15
- do I need a session-key to Get call?
You don't need to use a session key for authentication, but you do need to use some form of API authentication. When I'm making test calls, I find it easiest to use session key auth. To use OAuth, you'll need extended backend systems.
- how to get a session-key?
We walk through how to retrieve a session key in Session Key authentication.
Here is an example from the guide:
curl --location --request \
POST' https://[COMMUNITY DOMAIN]/restapi/vc/authentication/sessions/login' \
--form 'user.login=[USER NAME]' \
--form 'user.password=[PASSWORD]'
We've got some example GET cURL calls that include LiQL queries in The Community API v2 request. You'll need to URL encode the query, as shown here.
curl -L -X GET \
'httpS://[COMMUNITY DOMAIN]/api/2.0/search?q=SELECT%20count(*)%20FROM%20messages%20WHERE%20author.login%20%3D%20%27docadmin%27' \
-H 'li-api-session-key: [SESSION KEY]'
- how to code a curl call?
select id, name, node.id, role_status from roles where users.id = '17'
Here is what I used locally to test out your query:
Get a session key
curl -X POST https://my.qa.lithium.com/restapi/vc/authentication/sessions/login -H 'content-type: application/x-www-form-urlencoded' -d 'user.login=admin&user.password=mypassword'
This returned a session key.
Then I used an online URL encoder for the LiQL statement
select%20id%2C%20name%2C%20node.id%2C%20role_status%20from%20roles%20where%20users.id%20%3D%20%2717%27
Then I built my GET request in cURL like this
curl -L -X GET \
'https://my.qa.lithium.com/api/2.0/search?q=select%20id%2C%20name%2C%20node.id%2C%20role_status%20from%20roles%20where%20users.id%20%3D%20%2717%27' \
-H 'li-api-session-key: x5WMj36WEL9cvM7K1oUNLCnXXbRJQXwMbCI3PDhYO98.'
I got a successful response
{
"status":"success",
"message":"",
"http_code":200,
"data":{
"type":"roles",
"list_item_type":"role",
"size":10,
"items":[
{
"type":"role",
"id":"t:Administrator",
"name":"Administrator",
"role_status":"active",
"node":{
"type":"node",
"id":"community:Hawley2Community"
}
},
{
"type":"role",
"id":"t:BlogAuthor",
"name":"BlogAuthor",
"role_status":"active",
"node":{
"type":"node",
"id":"community:Hawley2Community"
}
},
{
"type":"role",
"id":"t:CIC",
"name":"CIC",
"role_status":"active",
"node":{
"type":"node",
"id":"community:Hawley2Community"
}
},
{
"type":"role",
"id":"t:CategoryExpert",
"name":"CategoryExpert",
"role_status":"active",
"node":{
"type":"node",
"id":"community:Hawley2Community"
}
},
{
"type":"role",
"id":"t:Lithium",
"name":"Lithium",
"role_status":"active",
"node":{
"type":"node",
"id":"community:Hawley2Community"
}
},
{
"type":"role",
"id":"b:BlogPremodSpam:BlogAuthor",
"name":"BlogAuthor",
"role_status":"active",
"node":{
"type":"node",
"id":"board:BlogPremodSpam"
}
},
{
"type":"role",
"id":"b:BlogPremodSpam:BlogModerator",
"name":"BlogModerator",
"role_status":"active",
"node":{
"type":"node",
"id":"board:BlogPremodSpam"
}
},
{
"type":"role",
"id":"c:suzieSandbox:CategoryExpert",
"name":"CategoryExpert",
"role_status":"active",
"node":{
"type":"node",
"id":"category:suzieSandbox"
}
},
{
"type":"role",
"id":"b:suziesBlog:BlogAuthor",
"name":"BlogAuthor",
"role_status":"active",
"node":{
"type":"node",
"id":"board:suziesBlog"
}
},
{
"type":"role",
"id":"b:suziesBlog:BlogModerator",
"name":"BlogModerator",
"role_status":"active",
"node":{
"type":"node",
"id":"board:suziesBlog"
}
}
]
},
"metadata":{
}
}
I hope this helps.