Company-scoped methods
Most of our API resources are not owned by the user, but by a company. This makes it possible for all the users who have access to a single company to interact with all the resources it owns (if the user has the related permissions, of course). This is why most of our methods are Company-scoped: it means that you need to provide an additional company_id parameter to use the method correctly.
The methods explained on this page provide some useful information other than the Company ID! Check the Plan Management page to know more about it!
🔬 Where can I find my company_id?
One of the questions that we receive more often is: "How can I find my company_id?"
Don't worry, it is really easy. You can list all the companies accessible by the user using the List User Companies method, which will return you an array of companies. Of course, this method is not company-scoped! 😁 You just need to select the right company from the returned list and extract its ID, and you're done!
If you're implementing a simple application for a single company, then you can use our API Reference or our Postman Collection to retrieve the Company ID, and then insert it as a constant in your code; this way, you'll avoid writing code to retrieve a value that will never change.
Otherwise, if you need to manage multiple company IDs that are unknown at developing time, then you can check the SDK examples below to retrieve the Company ID from your code.
Here you can find the steps to use the API Reference to retrieve the Company ID:
- Obtain a valid Access Token using one of the available methods;
- Open the Auth Section in the API Reference, and insert the copied access token in the "HTTP BEARER" Section (please, don't add "Bearer" to the token, the tool will take care of it!);
- Search the List User Companies method and click the "Try" button, the Company ID will be included in the obtained response.
Here you can find a few examples using our SDKs:
- C#
- Go
- Java
- JavaScript
- PHP
- Python
- Ruby
- TypeScript
using System.Collections.Generic;
using System.Diagnostics;
using It.FattureInCloud.Sdk.Api;
using It.FattureInCloud.Sdk.Client;
using It.FattureInCloud.Sdk.Model;
Configuration config = new Configuration();
// Check out the Authentication section to retrieve the Access Token
config.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new UserApi(config);
try
{
// List User Companies
ListUserCompaniesResponse result = apiInstance.ListUserCompanies();
// In the result you'll find a list of companies, you must use the "Id" field of one of those
Console.Write(result.Data.Companies[0].Id);
}
catch (ApiException e)
{
Console.Write("Exception when calling UserApi.ListUserCompanies: " + e.Message);
Console.Write("Status Code: " + e.ErrorCode);
Console.Write(e.StackTrace);
}
package main
import (
"context"
"fmt"
"os"
fattureincloudapi "github.com/fattureincloud/fattureincloud-go-sdk/v2/api"
fattureincloud "github.com/fattureincloud/fattureincloud-go-sdk/v2/model"
)
func main() {
// Check out the Authentication section to retrieve the Access Token
auth := context.WithValue(context.Background(), fattureincloudapi.ContextAccessToken, "ACCESS_TOKEN")
configuration := fattureincloudapi.NewConfiguration()
apiClient := fattureincloudapi.NewAPIClient(configuration)
resp, r, err := apiClient.UserAPI.ListUserCompanies(auth).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `UserAPI.ListUserCompanies``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `ListUserCompanies`: ListUserCompaniesResponse
// In the result you'll find a list of companies, you must use the "Id" field of one of those
fmt.Printf("%d", resp.GetData().GetCompanies()[0].GetId())
}
import it.fattureincloud.sdk.ApiClient;
import it.fattureincloud.sdk.ApiException;
import it.fattureincloud.sdk.Configuration;
import it.fattureincloud.sdk.auth.*;
import it.fattureincloud.sdk.models.*;
import it.fattureincloud.sdk.api.UserApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Check out the Authentication section to retrieve the Access Token
OAuth OAuth2AuthenticationCodeFlow = (OAuth) defaultClient.getAuthentication("OAuth2AuthenticationCodeFlow");
OAuth2AuthenticationCodeFlow.setAccessToken("YOUR ACCESS TOKEN");
UserApi apiInstance = new UserApi(defaultClient);
try {
ListUserCompaniesResponse result = apiInstance.listUserCompanies();
// In the result you'll find a list of companies, you must use the "id" field of one of those
System.out.println(result.getData().getCompanies().get(0).getId());
} catch (ApiException e) {
System.err.println("Exception when calling UserApi#listUserCompanies");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
import fattureInCloudSdk from "@fattureincloud/fattureincloud-js-sdk";
let defaultClient = fattureInCloudSdk.ApiClient.instance;
// Check out the Authentication section to retrieve the Access Token
let OAuth2AuthenticationCodeFlow =
defaultClient.authentications["OAuth2AuthenticationCodeFlow"];
OAuth2AuthenticationCodeFlow.accessToken = "YOUR ACCESS TOKEN";
let apiInstance = new fattureInCloudSdk.UserApi();
apiInstance.listUserCompanies().then(
(result) => {
// In the result you'll find a list of companies, you must use the "id" field of one of those
console.log(result.data.companies[0].id);
},
(error) => {
console.error(error);
}
);
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Check out the Authentication section to retrieve the Access Token
$config = FattureInCloud\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new FattureInCloud\Api\UserApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
try {
$result = $apiInstance->listUserCompanies();
// In the result you'll find a list of companies, you must use the "id" field of one of those
print_r($result->getData()->getCompanies()[0]->getId());
} catch (Exception $e) {
echo 'Exception when calling UserApi->listUserCompanies: ', $e->getMessage(), PHP_EOL;
}
from __future__ import print_function
import time
import os
import fattureincloud_python_sdk
from fattureincloud_python_sdk.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://api-v2.fattureincloud.it
# See configuration.py for a list of all supported configuration parameters.
configuration = fattureincloud_python_sdk.Configuration()
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Check out the Authentication section to retrieve the Access Token
configuration.access_token = os.environ["ACCESS_TOKEN"]
# Enter a context with an instance of the API client
with fattureincloud_python_sdk.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = fattureincloud_python_sdk.UserApi(api_client)
try:
# List User Companies
api_response = api_instance.list_user_companies()
# In the result you'll find a list of companies, you must use the "id" field of one of those
print(api_response.data.companies[0].id)
except Exception as e:
print("Exception when calling UserApi->list_user_companies: %s\n" % e)
require 'time'
require 'fattureincloud_ruby_sdk'
# setup authorization
FattureInCloud_Ruby_Sdk.configure do |config|
# Check out the Authentication section to retrieve the Access Token
config.access_token = 'YOUR ACCESS TOKEN'
end
api_instance = FattureInCloud_Ruby_Sdk::UserApi.new
begin
# List User Companies
result = api_instance.list_user_companies
# In the result you'll find a list of companies, you must use the "id" field of one of those
p result.data.companies[0].id
rescue FattureInCloud_Ruby_Sdk::ApiError => e
puts "Error when calling UserApi->list_user_companies: #{e}"
end
import { Configuration, UserApi } from "@fattureincloud/fattureincloud-ts-sdk";
// Check out the Authentication section to retrieve the Access Token
const apiConfig = new Configuration({
accessToken: "YOUR ACCESS TOKEN",
});
let apiInstance = new UserApi(apiConfig);
apiInstance.listUserCompanies().then(
(result) => {
// In the result you'll find a list of companies, you must use the "id" field of one of those
console.log(result.data.companies[0].id);
},
(error) => {
console.error(error);
}
);
You can set the Access Token in the dedicated section, for more informations look here.
If you want more examples, you can find them in the Readme file of each SDK or in the Quickstart section.
If you want to retrieve the details of a specific company, you can always use the Get Company Info method, but in this case, this method is company-scoped, so you need an ID! 😉