My Products
Help
Florian Haase
PARTNER

Service integration returns 401 in postman

by Florian Haase

Hi,

 

we also try to get started with the service integration but I only get 401 in Postman. Generating token work great now (that means that clientID/Secret/Scope and all should be in place).

 

But when posting:

{
availableCustomers(vismaNetCustomerId:3466752)
{
totalCount
items
{
name
vismaNetCustomerId
}
}
}

 

to https://business.visma.net/api/graphql

 

results in:

<html>

<head>
<title>401 Authorization Required</title>
</head>

<body>
<center>
<h1>401 Authorization Required</h1>
</center>
<hr>
<center>nginx</center>
</body>

</html>

 

We followed the documentation for setup of the user in VBNxt. But how should we proceed now. Token generation is working, but API answers with 401 - where do we start here?

 

Florian

6 REPLIES 6

by Øyvind Årseth (Updated ‎26-08-2022 16:03 by Øyvind Årseth VISMA )

Hi Florian

As I can see you already have the customerID, I suppose it is the available companies you are looking for? 
Try this: 
{
availableCompanies(customerNo: 3466752) {
totalCount
items {
name
vismaNetCompanyId
}
}
}
It should return at least one companyID, which you then should be able to proceed with - useCompany(no: xx) - where xx equals the companyID. 

Also, if you want to use client credentials, you need to use the service-API, as Ole points out. Otherwise, you are running in a user context. 

Florian Haase
PARTNER

Thank you Øyvind and Ole,

It's working now. I did not recognize that we used the wrong endpoint-address.

 

Florian

 

 

 

 

omelhus
PARTNER

by omelhus

Great. You can also fetch the correct endpoint from the Visma Connect token.

 

https://github.com/omelhus/VBNXT.Console/blob/master/src/VBNXT.Console/Program.cs#L35-L46

 

carbon(4).png

Florian Haase
PARTNER

by Florian Haase

AH okay, I see that the Visma Business NXT GraphQL API is missing in the Application Setup in addition the Visma Business NXT GraphQL Service API. But I can't choose it either.

 

FLorian      

Florian Haase
PARTNER

Does not work either when I create a new application. I'm also missing the following fields due to the documentation

FlorianHaase_0-1661522601962.png

 

omelhus
PARTNER

by omelhus (Updated ‎26-08-2022 16:01 by omelhus PARTNER )

You'll have to use a user context to fetch the correct customer number using the availableCustomers query, and then use the availableCompanies query to find what companies are available for that customer.

 

Use https://business.visma.net/api/graphql-service.

 

fragment VismaCompany on VbcCompany {
  name
  vismaNetCompanyId
}

query GetAvailableCompanies($customerNo: Long!) {
  availableCompanies(customerNo: $customerNo) {
    totalCount
    items {
      ...VismaCompany
    }
  }
}