→ 🚀Are you a Lansweeper Champion?! Join our Contributor Program Sign up here!

Community FAQ
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
MrNico
Engaged Sweeper II


Hello, I am trying to make a simple query through the lansweeper API, and I have not been able to do it. I want to obtain a list of the assets there are. For that I have created a user "Apiaccess" of the type "Personal Access Token" (PAT), I already have my access codes. but I don't know which URL I should send the query to. Could you tell me that please? Thanks PS: I can't find it in the documentation.

2 REPLIES 2
DavidPK
Lansweeper Tech Support
Lansweeper Tech Support

Hi Mr Nico

 

All of the necessary steps to start making API calls can be found under here: https://developer.lansweeper.com/docs/data-api/get-started/welcome/

 

Lansweeper Developer HubLansweeper Developer Hub

Welcome | Documentation – Lansweeper

Lansweeper's Data API enables you to programmatically interact with Lansweeper Sites, providing quick and easy access to Lansweeper's discovered IT, OT, and Cloud asset data.

 

The URL you should be using is https://api.lansweeper.com/api/v2/graphql

 

https://developer.lansweeper.com/docs/data-api/get-started/endpoint

Lansweeper Developer HubLansweeper Developer Hub

The GraphQL endpoint | Documentation – Lansweeper

MrNico
Engaged Sweeper II

Thanks for the help, I'm already making some progress, I'm creating a script in powershell that gives me all the inventory I have in lansweeper, the problem I have now is that when I run it it gives me an error "Invoke-RestMethod: {"errors" :[{"message":"Cannot query field 'allAssets' on type 'Query'."}]}"
I know these are basic questions, I'm not an expert in using APIs either, but I need to be able to do this, which I think is basic. What else could be going wrong?

My Script

$headers = @{
"Content-Type" = "application/json"
"Authorization" = "Token xxxxxxxxxxxxxxxxxxxxxxxx"
}

$query = @"
{
allAssets {
items {
id
name
type
status
}
}
}
"@

$body = @{
query = $query
} | ConvertTo-Json

$response = Invoke-RestMethod -Uri "https://api.lansweeper.com/api/v2/graphql" -Method Post -Headers $headers -Body $body -Verbose

if ($response -eq $null) {
Write-Output "Error."
} else {
$response
}

 

General Discussions

Find answers to technical questions about Lansweeper.

New to Lansweeper?

Try Lansweeper For Free

Experience Lansweeper with your own data.
Sign up now for a 14-day free trial.

Try Now