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.
๐ฟย One-shot methodsโ
The one-shot methods are the easier way to retrieve the Company ID, but they can be used only if you have control of all the companies that will use your integration.
For example, if you are developing a one-time script or an application that is meant to be used with a single company, we suggest you retrieve the Company ID once and hardcode it.
Similarly, while testing our APIs using Postman or our API Reference you will most probably deal with a single company, so you can retrieve the Company ID once and use it in your tests.
In this case, you can find your Company ID in two places.
The easier way is to access the Fatture in Cloud web application, you will find it at the top left of the page, next to the company name.
As an alternative, you can also use our Utilities tool to retrieve the Company ID, as explained here. Once the Login and Permission steps are completed, the Company ID will be shown on the page, so you just have to copy it and paste it into your code.
๐ย API methodโ
The API method is for sure the most complicated way to retrieve the Company ID, but at the same time, it is the most flexible way to obtain it, as it allows you to retrieve the ID dynamically.
For example, it is really useful if you don't know who will use your integration once published, and you want to provide the user with the list of Companies he can control through the Fatture in Cloud APIs.
You can dynamically list all the companies controlled by the current 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!
You can use the API method also for the use cases described in the previous section, for example using our API Reference or our Postman Collection to perform the API call, and then insert it as a constant in your code; these tools can also be used to test the API method before implementing it into 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 some examples, based on our SDKs, to retrieve the Company ID from your code.
- 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! ๐