prepaid-host/sevdesk-php-client

dev-main 2023-03-26 17:20 UTC

This package is not auto-updated.

Last update: 2024-09-23 23:09:51 UTC


README

联系:要联系我们的支持,请点击这里

# 一般信息 欢迎使用我们的API!
sevDesk为您提供通过接口检索数据的功能,即sevDesk API,并且可以在不使用Web UI的情况下进行更改。sevDesk接口是一个REST-Full API。所有在Web UI中使用的sevDesk数据和功能也可以通过API进行控制。# 跨域资源共享 此API具有跨域资源共享(CORS)功能。
它使浏览器能够进行跨域通信。
当使用此API检索资源时,您可能会在请求的资源中遇到嵌套资源。
例如,发票总是包含一个联系信息,您可以看到其ID和对象名称。
此API允许您将这些资源完全嵌入到最初请求的资源中。
以我们的发票为例,这意味着您不仅可以看到联系信息的ID和对象名称,还可以看到完整的联系资源。要嵌入资源,您只需在GET请求中添加查询参数'embed'。
作为值,您可以提供嵌套资源的名称。
也可以通过提供多个名称(以逗号分隔)来嵌入多个嵌套资源。# 身份验证和授权 sevDesk API使用令牌身份验证来授权调用。为此,每个sevDesk管理员都有一个API令牌,它是一个包含32个字符的十六进制字符串。以下片段显示了如果您是第一次使用我们的API,可以在哪里找到API令牌。


此令牌将需要在您发送的每个请求中,并且需要附加到请求URL作为查询参数
或作为授权头的值。
出于安全原因,我们建议将API令牌放在授权头中,而不是查询字符串中。
然而,在此文档中的请求示例中,我们将将其保留在查询字符串中,因为它更容易复制并尝试。
以下URL是一个示例,显示了您的令牌需要放置的位置作为查询参数。
在这种情况下,我们使用了某些随机的API令牌。

  • https://my.sevdesk.de/api/v1/Contact?token=b7794de0085f5cd00560f160f290af38
以下示例显示了授权头中的令牌。
  • "Authorization" :"b7794de0085f5cd00560f160f290af38"
API令牌的寿命无限,换句话说,只要sevDesk用户存在,它就存在。
因此,用户永远不应该被删除。
如果确实有必要,建议保存api令牌,因为我们无法在之后检索它!
还可以生成新的API令牌,例如,如果您想防止其他人通过获取您当前的API令牌来使用您的sevDesk帐户。
为了实现这一功能,您只需点击您令牌右侧的“生成新”符号,并用您的密码确认即可。# API 新闻 想要不再错过API新闻和更新,请订阅我们的免费API新闻通讯,获取所有相关资讯,确保您的sevDesk软件运行顺畅。要订阅,请简单点击这里并确认我们发送所有相关更新的电子邮件地址。# API 请求 在我们的案例中,REST API请求需要通过组合以下组件来构建。
注意:请通过“User-Agent”头传递有意义的条目。如果“User-Agent”设置得有意义,我们可以在客户查询时提供更好的支持。
以下是一个“User-Agent”可能的外观:“Integration-name by abc”。

以下是一个使用curl检索sevDesk中现有联系人的示例请求。

Get Request



如你所见,该请求包含上述提到的所有组件。
它的HTTP方法是GET,它有一个正确的端点(https://my.sevdesk.de/api/v1/Contact),查询参数如token以及额外的header信息!

查询参数

如您在上述示例请求中所见,除了“token”之外,URL中还有其他一些参数。
这些参数大多为可选,但它们对于许多请求非常有用,因为它们可以限制、扩展、排序或筛选您将获得的响应数据。

以下是sevDesk API最常用的三个查询参数。这是一个使用embed参数的示例。
以下第一个请求将返回sevDesk中所有公司联系条目,最多100条,没有任何附加信息,没有偏移量。



现在看看响应中位于category属性的位置。
自然地,它只包含对象的id和对象名称,但没有更多信息。
我们现在将使用值为"category"的embed参数。



如你所见,category对象现在扩展了,并显示了所有属性及其对应值。

还有许多其他查询参数可以用来过滤返回的数据,以便匹配特定模式的对象,但是这些将不会在这里提及,而是在最常用的API端点(如联系人、发票或收据)的详细文档中找到。

请求头部

HTTP请求(响应)头部允许客户端以及服务器在请求中传递额外的信息。
它们传递了在HTTP上传输数据时重要的参数和参数。
在使用sevDesk API时,以下三个头部有用/必要:“Authorization”,“Accept”和“Content-type”。
以下是对它们为什么以及如何使用的简要说明。

授权

如果您想在头部而不是URL中提供API令牌,则可以使用它。
  • 授权:yourApiToken
接受

指定响应的格式。
对于带有响应体的操作是必需的。
  • 接受:application/format
在我们的案例中,format可以被替换为jsonxml

内容类型

指定请求中使用的格式。
对于带有请求体的操作是必需的。
  • 内容类型:application/format
在我们的案例中,format可以被替换为jsonx-www-form-urlencoded

API响应

HTTP状态码
当调用sevDesk API时,您很可能会在响应中得到一个HTTP状态码。
某些API调用还会返回包含有关资源的信息的JSON响应体。
返回的每个状态码都将是一个成功代码或一个错误代码。

成功代码
错误代码 # 您的第一个请求 在阅读了我们的API介绍之后,您现在应该能够进行第一次调用。
为了测试我们的API,我们始终建议为sevDesk创建一个试用账户,以防止对您的主账户造成不必要的变化。
试用账户将处于最高档(物料管理),因此可以测试sevDesk的所有功能!

要开始测试,我们推荐以下工具之一以下示例将展示您的第一个请求,即在sevDesk中创建一个新的联系人。
  1. 下载适用于您所需系统的Postman并启动应用程序
  2. 将网址设置为 https://my.sevdesk.de/api/v1/Contact
  3. 使用连接符 ?token= 添加到网址末尾,或创建一个授权头。将您的API令牌作为值插入
  4. 对于此测试,选择HTTP方法为 POST
  5. 转到 Headers 并输入键值对 Content-type + application/x-www-form-urlencoded
    作为替代方案,您也可以直接转到 Body 并选择 x-www-form-urlencoded
  6. 现在转到 Body(如果您还未在那里),并输入以下图片中所示的关键值对



  7. 点击 发送。您的响应现在应该看起来像这样

如您所见,在这种情况下,成功的响应返回一个包含您刚刚创建的联系人信息的JSON格式的响应体。
为了简化,这只是一个创建联系人的最小示例。
然而,您可以提供许多参数组合,这些参数组合可以为您联系人添加信息。

此PHP包是由Swagger Codegen项目自动生成的

  • API版本:2.0.0
  • 构建包:io.swagger.codegen.v3.generators.php.PhpClientCodegen

要求

PHP 5.5及更高版本

安装与使用

Composer

要通过Composer安装绑定,请将以下内容添加到composer.json

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
    }
  ],
  "require": {
    "GIT_USER_ID/GIT_REPO_ID": "*@dev"
  }
}

然后运行composer install

手动安装

下载文件并包含autoload.php

    require_once('/path/to/SwaggerClient-php/vendor/autoload.php');

测试

要运行单元测试

composer install
./vendor/bin/phpunit

入门

请遵循安装过程,然后运行以下命令

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: api_key
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');

$apiInstance = new Swagger\Client\Api\AccountingContactApi(
    // 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
);
$body = new \Swagger\Client\Model\ModelAccountingContact(); // \Swagger\Client\Model\ModelAccountingContact | Creation data

try {
    $result = $apiInstance->createAccountingContact($body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AccountingContactApi->createAccountingContact: ', $e->getMessage(), PHP_EOL;
}

// Configure API key authorization: api_key
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');

$apiInstance = new Swagger\Client\Api\AccountingContactApi(
    // 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
);
$accounting_contact_id = 56; // int | Id of accounting contact resource to delete

try {
    $result = $apiInstance->deleteAccountingContact($accounting_contact_id);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AccountingContactApi->deleteAccountingContact: ', $e->getMessage(), PHP_EOL;
}

// Configure API key authorization: api_key
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');

$apiInstance = new Swagger\Client\Api\AccountingContactApi(
    // 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
);
$contact_id = "contact_id_example"; // string | ID of contact for which you want the accounting contact.
$contact_object_name = "contact_object_name_example"; // string | Object name. Only needed if you also defined the ID of a contact.

try {
    $result = $apiInstance->getAccountingContact($contact_id, $contact_object_name);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AccountingContactApi->getAccountingContact: ', $e->getMessage(), PHP_EOL;
}

// Configure API key authorization: api_key
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');

$apiInstance = new Swagger\Client\Api\AccountingContactApi(
    // 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
);
$accounting_contact_id = 56; // int | ID of accounting contact to return

try {
    $result = $apiInstance->getAccountingContactById($accounting_contact_id);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AccountingContactApi->getAccountingContactById: ', $e->getMessage(), PHP_EOL;
}

// Configure API key authorization: api_key
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');

$apiInstance = new Swagger\Client\Api\AccountingContactApi(
    // 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
);
$accounting_contact_id = 56; // int | ID of accounting contact to update
$body = new \Swagger\Client\Model\ModelAccountingContactUpdate(); // \Swagger\Client\Model\ModelAccountingContactUpdate | Update data

try {
    $result = $apiInstance->updateAccountingContact($accounting_contact_id, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AccountingContactApi->updateAccountingContact: ', $e->getMessage(), PHP_EOL;
}
?>

API端点文档

所有URI都相对于https://my.sevdesk.de/api/v1

模型文档

授权说明文档

api_key

  • 类型:API密钥
  • API密钥参数名称:授权
  • 位置:HTTP头部

作者