Solved
Forum Discussion
beefjorgensen
1 month agoContributor
How do you pass session-key in a GraphQL search request?
HussnainI
1 month agoKhoros Staff
Hey beefjorgensen,
Pass the session key as an HTTP header named `li-api-session-key`.
Example:
curl -X POST 'https://your-community.com/api/2.1/graphql' \
-H 'Content-Type: application/json' \
-H 'li-api-session-key: YOUR_SESSION_KEY_HERE' \
-d '{ "query": "query MessageSearch($searchTerm: String!)
{ messageSearch(searchTerm: $searchTerm, first: 10)
{ results { edges { node { ... on TopLevelMessageSearchResult { message { id subject } } } } } } }",
"variables": {"searchTerm": "your search term"} }'
To obtain a session key:
POST /restapi/vc/authentication/sessions/login?restapi.response_format=json.v3
Content-Type: application/x-www-form-urlencoded
user.login=username&user.password=password
Example:
curl -s -X POST 'https://<your-community>.com/restapi/vc/authentication/sessions/login?restapi.response_format=json.v3' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'user.login=$USERNAME&user.password=$PASSWORD'
Response: { "response": { "status": "success", "value": { "$": "your-session-key-here" } } }
The session key will be in the response at `response.value.$`.
Please ping me if you have more questions.