Skip to content

Commit 42f7737

Browse files
authored
Merge pull request #382 from ynput/360-outdated-example-of-cpp-api
360 fix outdated example of cpp api
2 parents faa643e + b9a072c commit 42f7737

1 file changed

Lines changed: 85 additions & 66 deletions

File tree

website/docs/dev_api_cpp.md

Lines changed: 85 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,73 @@ description: Information about AYON C++ API
66
toc_max_heading_level: 5
77
---
88

9+
import Tabs from '@theme/Tabs';
10+
import TabItem from '@theme/TabItem';
11+
912
## About AYON C++ API
1013

11-
The AYON CPP API allows communication with the AYON server.
14+
The AYON CPP API is a static lib. It allows communication with the AYON server.
1215
Implementation is mainly focused on [AYON USD Resolver](dev_api_usd_resolver.md) to communicate with the server resolve endpoint.
1316

14-
## Get Started
15-
1617
:::tip Development Environment
17-
We assume you already have setup your c++ dev environment as well as cmake.
18+
We assume you already have setup your C++ dev environment as well as cmake.
19+
You need to use at least C++17 in CMake
1820
:::
1921

20-
### Fetch and Build The library
21-
AYON CPP API is a static lib.
22-
23-
You need to build it first. We've prepared python script to do the hard lifting for you.
24-
25-
```shell
26-
git clone --recurse-submodules https://github.com/ynput/ayon-cpp-api.git
27-
cd ayon-cpp-api
28-
python AyonBuild.py setup
29-
python AyonBuild.py runStageGRP CleanBuild
30-
```
3122

32-
### Include it in your cmake projects
23+
## C++ Example Project
3324

34-
Once you include it and build your cpp project you'll no longer need the library.
25+
Once built, you can then start including it in your cpp projects.
3526

36-
<details><summary>A CPP Example</summary>
27+
<Tabs>
28+
<TabItem value="Project Structure" label="Project Structure" default>
3729

38-
Here's an example cpp project structure
3930
```
4031
.
4132
├─ ext/ayon-cpp-api
4233
├─ CMakelists.txt
4334
└─ main.cpp
4435
```
36+
</TabItem>
37+
<TabItem value="main.cpp" label="main.cpp" default>
4538

46-
#### Fetch Dependencies
47-
48-
Please refer to [Fetch and Build The library](#fetch-and-build-the-library) section above for the instructions
49-
and repeat them inside `ext` folder in your project folder.
50-
51-
#### CPP Project Files
52-
53-
```cpp title="main.cpp"
39+
```cpp
5440
// AYON CPP API Test
41+
#include <iostream>
5542
#include "AyonCppApi.h"
5643

5744
int main (){
58-
AyonApi con = AyonApi();
45+
std::string project_name = "" ;
46+
std::cout << "Enter a project: ";
47+
std::cin >> project_name;
48+
49+
AyonApi con = AyonApi(
50+
"log/log.json", // extension will be always changed to json
51+
"your_access_token", // This is a Bearer access token not AYON_API_KEY
52+
"https://your.server", // with No trailing or forward slash at the end.
53+
project_name,
54+
"your-site-id" // Your site id e.g. military-mouse-of-jest
55+
);
56+
57+
std::string uri = "" ;
58+
std::cout << "Enter a uri to resolve: ";
59+
std::cin >> uri;
60+
61+
std::pair<std::string, std::string> resolvedAsset = con.resolvePath(uri);
62+
std::cout << "The resolved path: " << resolvedAsset.second << std::endl;
5963
return 0;
6064
}
6165
```
66+
:::caution
67+
68+
The auth key used in the cpp example is an [Authentication Token](https://community.ynput.io/t/ayon-rest-api-guide/1268#get-authentication-token-6) which is not an `AYON_API_KEY`.
69+
Also, don't add a trailing forward slash to your AYON server URL.
70+
:::
71+
72+
</TabItem>
73+
<TabItem value="CMakeLists.txt" label="CMakeLists.txt">
6274

63-
```shell title="CMakelists.txt"
75+
```shell
6476
cmake_minimum_required(VERSION "3.28.1")
6577

6678
set(CMAKE_CXX_STANDARD 17)
@@ -71,48 +83,55 @@ project(main)
7183
# Include AyonCppApi
7284
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/ext/ayon-cpp-api")
7385
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/ext/ayon-cpp-api")
86+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/ext/ayon-cpp-api/ext/ayon-cpp-dev-tools/src/")
7487

7588
add_executable(${PROJECT_NAME} main.cpp)
7689

7790
target_link_libraries(${PROJECT_NAME} AyonCppApi)
7891
```
79-
80-
#### Build the project
81-
82-
> I'm using `VS studio` (devenv.exe) on my side.
83-
84-
```shell
85-
cmake -S . -B build -DJTRACE=0
86-
devenv build/main.sln /Build
87-
```
88-
89-
#### Test Run
90-
91-
you'd need to set few environment variables.
92-
otherwise, it won't work.
93-
94-
```shell
95-
set AYON_SERVER_URL=<your ayon server url>
96-
set AYON_API_KEY=<your server api key>
97-
set AYON_PROJECT_NAME=<project name>
98-
set AYON_SITE_ID=<site id> # e.g. military-mouse-of-jest
99-
100-
build\Debug\main.exe
101-
```
102-
103-
Expected Output
104-
```shell
105-
my_cpp_project> build\Debug\main.exe
106-
[2024-09-20 15:59:31.541] [info] Loaded AYON_API_KEY and AYON_SERVER_URL
107-
[2024-09-20 15:59:31.542] [info] Found SideId
108-
```
109-
110-
:::tip `AYON_SITE_ID` fallback
111-
When skipping setting `AYON_SITE_ID` env variable, the lib will default to file named `site_id` *without an extension*.
112-
located at `%AppData%/Roaming/AYON/site_id` on windows.
113-
:::
114-
115-
</details>
92+
</TabItem>
93+
</Tabs>
94+
95+
*This example is brought from: [test_cpp_api](https://github.com/MustafaJafar/ayon-recipes/tree/main/test_cpp_api).*
96+
97+
98+
### Build And Run Commands
99+
100+
- **Fetch AYON CPP Repo**
101+
```
102+
cd ext
103+
git clone https://github.com/ynput/ayon-cpp-api.git --recurse-submodules
104+
```
105+
- **Build CPP** <br/>
106+
`ayon-cpp-api` repo provides python script to do the hard lifting for you.
107+
```
108+
cd ext\ayon-cpp-api
109+
python AyonBuild.py --setup
110+
python AyonBuild.py --runStageGRP CleanBuild
111+
```
112+
- **Build CPP Example**
113+
```
114+
rmdir /s /q build
115+
cmake -S . -B build -DJTRACE=0
116+
cmake --build ./build --config Debug -j12
117+
```
118+
- **Run CPP Example**
119+
```
120+
build\Debug\main.exe
121+
```
122+
- **Example Output**
123+
```
124+
Enter a project: Animal_Logic_ALab
125+
Enter a uri to resolve: ayon+entity://Animal_Logic_ALab/assets/book_encyclopedia01?product=usdAsset&version=v002&representation=usd
126+
The resolved path: H:\AYON\projects\Animal_Logic_ALab\assets\book_encyclopedia01\publish\usd\usdAsset\v002\ALA_book_encyclopedia01_usdAsset_v002.usd
127+
```
128+
- **Example contents of `log.json`**
129+
```json
130+
{"timestamp":"2025-04-07 13:24:48.368","level":"info","Thread Id":"5832","Process Id":"13732","message":"Connected to the Ayon server : 200"}
131+
{"timestamp":"2025-07-18 18:14:56.645","level":"warning","Thread Id":"34840","Process Id":"40096","message":"asset identification cant be generated {"entities":[],"error":"Invalid scheme: h","uri":"H:\\AYON\\projects\\Animal_Logic_ALab\\assets\\book_encyclopedia01\\publish\\usd\\usdAsset\\v002\\ALA_book_encyclopedia01_usdAsset_v002.usd"}"}
132+
{"timestamp":"2025-07-18 18:16:17.522","level":"warning","Thread Id":"564","Process Id":"37400","message":"asset identification cant be generated {"entities":[{}],"uri":"ayon+entity://Animal_Logic_ALab/assets/book_encyclopedia01?product=usdAsset"}"}
133+
{"timestamp":"2025-07-18 18:16:48.017","level":"warning","Thread Id":"33948","Process Id":"38436","message":"asset identification cant be generated {"entities":[],"error":"Invalid scheme: ","uri":"{root[work]}/Animal_Logic_ALab/assets/book_encyclopedia01/work/lookdev/ALA_book_encyclopedia01_lookdev_v001.hip"}"}
134+
```
116135
117136
## Learn More
118137

0 commit comments

Comments
 (0)