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.
🔬 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! 😉
🙋♂️ How can I know if a method is company-scoped?
The majority of our methods are company-scoped, so there's a high probability that the method you need to use is included in this group. If you want to be sure if your API method is actually company-scoped, you just need to check if it requires a company_id parameter.
In order to do it, you have a few possibilities:
🌍 Check on the API Reference
This is the easier option, that only requires you to search the method on our API Reference section. For example, let's check the List Issued Documents method. Checking the URL on top of the page, you can notice that it contains the /c/{company_id} portion, indicating that it is a company-scoped URL that requires to substitute the placeholder to be executed correctly.
On the same page, you can also check if you have a company_id box in the Path Params section: here you must insert your companyid while trying to use the API method using the _Try button.
💼 Check on your SDK documentation
If you're using a specific SDK, probably it will be easier for you to take advantage of it to check if a method is company-scoped: all the methods that are in this category require an integer company_id to be executed correctly. You can check if the company_id parameter is required by checking the signature of your method (for example using your IDE's functionalities) or accessing your SDK's documentation. Read your SDK's page for further info.
For example, using our PHP SDK you have two alternatives:
- Accessing the GitHub page of the List Issued Documents method and check if it requires the company_id parameter
- Use your favorite IDE to check if the method requires it, without having to access our documentation online
- Some of the SDKs provide standard documentation for the language they're based on; for example, Java's JavaDoc or Ruby's RubyDoc.
📬 Check our Postman Collection
If you're testing our API using our Postman Collection, you can check if the method needs the companyid parameter. You can check if the method's URL includes the /c/:company_id portion, where :companyid is the placeholder that must be replaced with the actual numeric ID:
Otherwise, similarly to what you can do in our API Reference section, you can just search for a companyid param in the _Path Variables section.
📝 Check our OpenAPI file
This is probably the most complicated method because it requires you to know how to read an OpenAPI file (or at least a YAML file) or to use an OpenAPI editor; at the same time, this is our source of truth: all the previous method derive from our OpenAPI specification, so this is where the companyid param is defined. Checking our OpenAPI Specification, you can find out if our method requires a company_id parameter by checking the _openapi.yaml file: below you can notice that the URL contains the {company_id} placeholder and that the company_id param is listed in the parameters section.
/c/\{company_id\}/issued_documents:
parameters:
- $ref: "#/components/parameters/company_id"
get:
summary: List Issued Documents
tags:
- Issued Documents
responses:
"200":
$ref: "#/components/responses/ListIssuedDocumentsResponse"