Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,61 +1,54 @@
---
title: How to add a document with an attachment via Rest API
description: The article describes how to add a new entry with an attachment in the Documents module via Rest API.
title: Jak przez API utworzyć dokument z załącznikiem
description: W tym artykule znajdziesz informacje, jak za pomocą REST API dodać rekord w module Dokumenty wraz z załącznikiem
keywords:
- Webservice
- API
- RestAPI
- add
- document
- file
- attachment
- dodać
- dokument
- plik
- załącznik
- YetiForce
tags:
- Webservice
- API
- Rest API
- Document with an attachment
- Dokument z załącznikiem
---

:::tip

This functionality is available for YetiForce version `6.2.0` and later

:::tip Funkcjonalność dostępna od wersji YetiForce `6.2.0` i później
:::

The article describes how to add a new entry with an attachment in the Documents module via Rest API.
Niniejszy artykuł przedstawia instrukcję, jak za pomocą API dodać rekord w module Dokumenty wraz z załącznikiem.

Before continuing, please research the methods and ways of communication described here: https://doc.yetiforce.com/api/
**Przed przejściem dalej należy zapoznać się z dostępnymi metodami i sposobem komunikacji z API opisanymi w [dokumentacji API](https://doc.yetiforce.com/api/).**

## 1. Create a document with an attachment
## 1. Tworzenie dokumentu wraz z załączeniem pliku

To create an entry in the Documents module use an API method the allows for record creation, i.e.
Do utworzenia rekordu w module Dokumenty należy wykorzystać metodę API umożliwiającą tworzenie rekordu, tj.

![create-record](create-record.png)

https://doc.yetiforce.com/api/#/BaseModule/ea3b9bea091cbde741323b5393901825

The difficult part when adding an attachment is the correct formulation of the query. As a standard, the module fields should be properly completed in the query, and in this case it will be no different.

Field names are available in the field edition panel in Software configuration → Standard modules → Edit fields
Utworzenie nowego rekordu w module Dokumenty wymaga podania następujących wartości:

Fields responsible for adding an attachment:
- `notes_title` - nazwa dokumentu.

- File type [filelocationtype]
- `folderid` - identyfikator katalogu.

This field defines the type of attachment. Two values are available: I - Internal, E - External
- `filelocationtype` - typ pliku. Pole to określa typ załącznika. Dostępne są dwie wartości: `I` - wewnętrzny (załącznik), `E` - zewnętrzny (odnośnik).

- File name/WWW [filename]
- `filename` - plik lub adres URL. Załącznik lub odnośnik.

Attachment or link

Once you know what the structure of the Documents module looks like, you can proceed with API queries. Below you can find some examples of this type of queries:
Poniżej przedstawiono kilka przykładów konstrukcji zapytań API:

### Postman

![create record Postman](create-record-PostmanApiDoc2.png)

### Guzzle, PHP HTTP client
### Guzzle - klient HTTP dla PHP

https://github.com/guzzle/guzzle

Expand Down Expand Up @@ -85,7 +78,7 @@ $options['multipart'] = [
$response = $httpClient->request('POST', $uri, $options)->getBody()->getContents();
```

### cURL, PHP
### cURL - PHP

```php
$url = 'https://example.com/webservice/RestApi/Documents/Record';
Expand All @@ -111,31 +104,19 @@ curl_setopt($ch, CURLOPT_POSTFIELDS, ['notes_title' => 'Document pdf', 'fileloca
$response = curl_exec($ch);
```

## 2. Relating a document to another entry

The existence of an unrelated document in the system is pointless, therefore each entry in the Documents module should be related to a record in another module, for example Contact, Account, Ticket, or any other that can be related to a Document.

You don't have to create separate API queries to relate the document, you can do it at the time of creating the document by adding a few additional variables, such as:

- relationOperation (bool) /mandatory

Determines that the created entry can be related

- sourceModule (string) /mandatory

Name of the module that the document should be related to
## 2. Powiązanie utworzonego dokumentu z innym wpisem

- sourceRecord (int) /mandatory
Aby powiązać tworzony dokument z innym rekordem w systemie, do zapytania API z pkt. 1 należy dodać:

ID of the record that the document should be related to
- `relationOperation` (bool) - ustawiając wartość `true`, określamy, że tworzony wpis podlega powiązaniu w relacji.

- relationId (int) /optional
- `sourceModule` (string) - nazwa modułu, z którym należy powiązać utworzony dokument.

ID of the relation between modules
- `sourceRecord` (int) - identyfikator rekordu, z którym należy powiązać utworzony dokument.

Mandatory if there are more than one relation between modules
- `relationId` (int) - opcjonalne, identyfikator relacji między modułami. Uzupełniamy, jeśli istnieje więcej niż jedna relacja między modułami.

Example:
Przykładowa konstrukcja zapytania z powiązaniem relacji:

```php
$httpClient = new \GuzzleHttp\Client($options);
Expand Down
52 changes: 23 additions & 29 deletions docs/4-developer-guides/2-api/3-how-to-add-graphic-file.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
title: How to add an image via Rest API
description: This article describes how to add images via Rest API in fields that support such files in YetiForce.
title: Jak przez API dodać do pola plik graficzny
description: Niniejszy dokument zawiera informacje, jak za pomocą REST API dodać plik graficzny w polach obsługujących takie pliki w YetiForce CRM.
keywords:
- Webservice
- API
- RestAPI
- add
- file
- attachment
- image
- field
- dodać
- plik
- załącznik
- graficzny
- pole
- YetiForce
tags:
- Webservice
Expand All @@ -18,39 +18,33 @@ tags:
- Image
---

This article describes how to add images via Rest API in fields that support such files in YetiForce.
Niniejszy dokument zawiera instrukcję, jak do rekordu za pomocą API dodać plik graficzny w polach obsługujących takie pliki.

The application has two types of fields that support graphic files, namely:
**Przed przejściem dalej należy zapoznać się z dostępnymi metodami i sposobem komunikacji z API opisanymi w [dokumentacji API](https://doc.yetiforce.com/api/).**

- Image
- Image (many)
Aplikacja YetiForce posiada dwa rodzaje pól obsługujących pliki graficzne:

![graphic file](graphic-file.png)

**Before continuing, please research the methods and ways of communication described here: https://doc.yetiforce.com/api/**

## Adding an image
- Plik graficzny
- Plik graficzny (wiele)

The difficulty with adding a graphic file is the proper preparation of fields in the query. At the beginning, you should prepare a list of fields that should be completed when creating / editing a record via API.

Module field structure can be found in the field edition panel in [Software configuration → Standard modules → Edit fields](/administrator-guides/standard-modules/edit-fields/).

Once you're familiar with the structure you can move on to constructing the queries.
![graphic file](graphic-file.png)

Each graphic file created at the API level requires three variables:
## Dodawanie pliku graficznego

- **name**
W celu dodania pliku graficznego do rekordu należy skorzystać ze standardowego punktu końcowego do tworzenia lub edycji rekordu poprzez metodę POST (tworzenie) lub PUT (edycja).

File name
```bash
/webservice/WebserviceStandard/{moduleName}/Record
```

- **key**
Pole z plikiem dodaje się analogicznie jak inne pola rekordu, z tą różnicą, że jego wartością nie jest łańcuch tekstowy lub liczba, lecz tablica z obiektem. Obiekt pliku graficznego tworzonego z poziomu API wymaga trzech elementów:

Random of characters string, unique within the pool of graphic files of a given field
- `name` - nazwa pliku.

- **baseContent**
- `key` - losowy ciąg znaków, niepowtarzalny w obrębie plików graficznych danego pola.

Graphic file converted to base64
- `baseContent` - plik graficzny przekonwertowany na format base64. Nie należy umieszczać fragmentu początkowego z typem MIME (np. `data:image/jpeg;base64,`).

Below you can find an example of an image added to a Contact using Postman:
Poniżej przedstawiono przykład dodania pliku graficznego do kontaktu za pomocą narzędzia Postman, gdzie `imagename` to nazwa pola określona w ustawieniach modułu.

![graphic file postman](graphic-file-postman.png)