Updated API Code Samples (#24141)

* api: remove PHP code samples

* api: remove Curl code samples

* api: remove Go code samples

* link out to marketplace exclusively for community-built drivers

* absolute path to V4_SRC

* programmatically extract x-codeSamples

* initial batch of examples

* Update api/server/main.go

Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>

* Update api/server/main.go

Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>

* Update api/server/main.go

Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>

* updated examples

---------

Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
This commit is contained in:
Jesse Hallam 2023-08-03 12:45:10 -03:00 committed by GitHub
parent 72b648cf81
commit 885802eae7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 847 additions and 5224 deletions

View File

@ -1,9 +1,11 @@
ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
.PHONY: build build-v4 clean playbooks
V4_YAML = v4/html/static/mattermost-openapi-v4.yaml
V4_YAML = $(ROOT)/v4/html/static/mattermost-openapi-v4.yaml
V4_SRC = v4/source
PLAYBOOKS_SRC = playbooks
V4_SRC = $(ROOT)/v4/source
PLAYBOOKS_SRC = $(ROOT)/playbooks
build: build-v4
@ -50,6 +52,8 @@ build-v4: node_modules playbooks
@cat $(V4_SRC)/exports.yaml >> $(V4_YAML)
@if [ -r $(PLAYBOOKS_SRC)/paths.yaml ]; then cat $(PLAYBOOKS_SRC)/paths.yaml >> $(V4_YAML); fi
@if [ -r $(PLAYBOOKS_SRC)/merged-definitions.yaml ]; then cat $(PLAYBOOKS_SRC)/merged-definitions.yaml >> $(V4_YAML); else cat $(V4_SRC)/definitions.yaml >> $(V4_YAML); fi
@echo Extracting code samples
cd server && go run . $(V4_YAML)
@node_modules/.bin/swagger-cli validate $(V4_YAML)
@node_modules/.bin/redoc-cli -t ./v4/html/ssr_template.hbs build ./v4/html/static/mattermost-openapi-v4.yaml -o ./v4/html/index.html --options.noAutoAuth --options.suppressWarnings
@ -74,5 +78,5 @@ clean:
playbooks:
@echo Fetching Playbooks OpenAPI spec
cd playbooks && node extract.js
cd playbooks && node merge-definitions.js ../$(V4_SRC)/definitions.yaml
cd playbooks && node merge-tags.js ../$(V4_SRC)/introduction.yaml
cd playbooks && node merge-definitions.js $(V4_SRC)/definitions.yaml
cd playbooks && node merge-tags.js $(V4_SRC)/introduction.yaml

19
api/server/go.mod Normal file
View File

@ -0,0 +1,19 @@
module github.com/mattermost/mattermost/api/internal
go 1.20
require (
github.com/pb33f/libopenapi v0.9.6
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e
)
require (
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

137
api/server/go.sum Normal file
View File

@ -0,0 +1,137 @@
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960/go.mod h1:9HQzr9D/0PGwMEbC3d5AB7oi67+h4TsQqItC1GVYG58=
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 h1:PRxIJD8XjimM5aTknUK9w6DHLDox2r2M3DI4i2pnd3w=
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936/go.mod h1:ttYvX5qlB+mlV1okblJqcSMtR4c52UKxDiX9GRBS8+Q=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/pb33f/libopenapi v0.9.6 h1:PqNqdBk0lqr/luxDLv8HPKFEJ4i0zf/hpyXqQ4r8jbM=
github.com/pb33f/libopenapi v0.9.6/go.mod h1:8lr9sjsI5uZxtiEvHgg1A9/p/70briQ5WUGoJiuTFPc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk=
github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e h1:4nW4NLDYnU28ojHaHO8OVxFHk/aQ33U01a9cjED+pzE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20191026110619-0b21df46bc1d/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

188
api/server/main.go Normal file
View File

@ -0,0 +1,188 @@
package main
import (
"bytes"
"log"
"os"
"text/template"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"github.com/pb33f/libopenapi"
v3high "github.com/pb33f/libopenapi/datamodel/high/v3"
"golang.org/x/tools/imports"
)
// exampleText defines the template in which the corresponding ExampleClient4_* body is wrapped.
const exampleText = `
package main
import (
{{- range .Imports -}}
{{- if .}}
{{"\t"}}{{.}}
{{- else}}
{{"\t"}}{{end -}}
{{- end}}
)
func main() {
{{.Body -}}
}`
func main() {
var exampleTmpl = template.Must(template.New("example").Parse(exampleText))
if len(os.Args) <= 1 {
log.Fatal("Expected filename to APIv4 spec as argument")
}
filename := os.Args[1]
data, err := os.ReadFile(filename)
if err != nil {
log.Fatalf("failed to read %s: %s", filename, err)
}
// Parse the Open APIv4 Spec
document, err := libopenapi.NewDocument(data)
if err != nil {
log.Fatalf("Failed to parse OpenAPI spec: %s", err)
}
v3Model, errors := document.BuildV3Model()
if len(errors) > 0 {
for i := range errors {
log.Printf("error: %s\n", errors[i])
}
log.Fatalf("cannot create v3 model from document: %d errors reported", len(errors))
}
applyExamples(v3Model, exampleTmpl)
// Re-render the file with the injected examples.
newDocument, _, _, errors := document.RenderAndReload()
if len(errors) > 0 {
for _, err := range errors {
log.Printf("error: %s\n", err)
}
log.Fatalf("cannot render document: %d errors reported", len(errors))
}
err = os.WriteFile(filename, newDocument, 0644)
if err != nil {
log.Fatal(err)
}
}
func applyExamples(v3Model *libopenapi.DocumentModel[v3high.Document], tmpl *template.Template) {
fileSet, modelFuncs, err := getModelFuncs()
if err != nil {
log.Fatalf("Failed to parse example funcs: %s", err)
}
for _, path := range v3Model.Model.Paths.PathItems {
applyExample(tmpl, fileSet, modelFuncs, path.Get)
applyExample(tmpl, fileSet, modelFuncs, path.Post)
applyExample(tmpl, fileSet, modelFuncs, path.Delete)
applyExample(tmpl, fileSet, modelFuncs, path.Options)
applyExample(tmpl, fileSet, modelFuncs, path.Head)
applyExample(tmpl, fileSet, modelFuncs, path.Patch)
applyExample(tmpl, fileSet, modelFuncs, path.Trace)
}
}
// applyExample looks through the functions in model_test to find an ExampleClient4_* matching the
// operation's unique identifier.
func applyExample(tmpl *template.Template, fileSet *token.FileSet, exampleFuncs []modelFunc, operation *v3high.Operation) {
// Not all of GET, POST, OPTIONS, etc. are defined for each operation.
if operation == nil {
return
}
var exampleFunction modelFunc
var found = false
for _, e := range exampleFuncs {
if e.FuncDecl.Name.Name == "ExampleClient4_"+operation.OperationId {
exampleFunction = e
found = true
break
}
}
if !found {
return
}
// Find all the imports used by the function so we can re-create a minimal example.
var fileImports []string
for _, i := range exampleFunction.File.Imports {
fileImports = append(fileImports, i.Path.Value)
}
// Render the example body using the template.
var body bytes.Buffer
err := printer.Fprint(&body, fileSet, exampleFunction.FuncDecl.Body.List)
if err != nil {
log.Fatal(err)
}
data := struct {
Imports []string
Body string
}{
fileImports,
body.String(),
}
// Process the resulting Go file to get the right indention, minimal set of imports, etc.
var unformattedExample bytes.Buffer
if err := tmpl.Execute(&unformattedExample, data); err != nil {
log.Fatalf("failed to render template: %v", err)
}
ignoredFilePath := "path"
example, err := imports.Process(ignoredFilePath, unformattedExample.Bytes(), nil)
if err != nil {
log.Fatal(err)
}
// Inject the resulting code sample
operation.Extensions["x-codeSamples"] = []struct {
Lang string
Source string
}{
{
Lang: "Go",
Source: string(example),
},
}
}
type modelFunc struct {
File *ast.File
FuncDecl *ast.FuncDecl
}
// getModelFuncs builds a fileset and function declaration set for the model/model_test packages.
func getModelFuncs() (*token.FileSet, []modelFunc, error) {
fileSet := token.NewFileSet()
packs, err := parser.ParseDir(fileSet, "../../server/public/model", nil, 0)
if err != nil {
return nil, nil, err
}
var examples []modelFunc
for _, pack := range packs {
for _, f := range pack.Files {
for _, d := range f.Decls {
if fn, isFn := d.(*ast.FuncDecl); isFn {
examples = append(examples, modelFunc{f, fn})
}
}
}
}
return fileSet, examples, nil
}

View File

@ -38,33 +38,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$resp = $driver->getBotModel()->createBot([
"username" => "userbot",
"display_name" => "AwesomeBot",
"description" => "test bot"
]);
if ($resp->getStatusCode() == 200) {
$createdBot = json_decode($resp->getBody());
}
get:
tags:
- bots
@ -118,34 +91,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$resp = $driver->getBotModel()->getBots([
"page" => 0,
"per_page" => 60,
"include_deleted" => true,
"only_orphaned" => true,
]);
if ($resp->getStatusCode() == 200) {
$bots = json_decode($resp->getBody());
}
"/api/v4/bots/{bot_user_id}":
put:
tags:
@ -198,35 +143,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$botUserID = "4xp9fdt77pncbef59f4k1qe83o";
$resp = $driver->getBotModel()->patchBot($botUserID, [
"username" => "userbot2",
"display_name" => "AwesomeBot2",
"description" => "test bot2"
]);
if ($resp->getStatusCode() == 200) {
$bot = json_decode($resp->getBody());
}
get:
tags:
- bots
@ -265,33 +181,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$botUserID = "4xp9fdt77pncbef59f4k1qe83o";
$resp = $driver->getBotModel()->getBot($botUserID, [
"include_deleted" => true,
]);
if ($resp->getStatusCode() == 200) {
$bot = json_decode($resp->getBody());
}
"/api/v4/bots/{bot_user_id}/disable":
post:
tags:
@ -323,31 +212,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$botUserID = "4xp9fdt77pncbef59f4k1qe83o";
$resp = $driver->getBotModel()->disableBot($botUserID);
if ($resp->getStatusCode() == 200) {
$disabledBot = json_decode($resp->getBody());
}
"/api/v4/bots/{bot_user_id}/enable":
post:
tags:
@ -379,31 +243,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$botUserID = "4xp9fdt77pncbef59f4k1qe83o";
$resp = $driver->getBotModel()->enableBot($botUserID);
if ($resp->getStatusCode() == 200) {
$enabledBot = json_decode($resp->getBody());
}
"/api/v4/bots/{bot_user_id}/assign/{user_id}":
post:
tags:
@ -441,32 +280,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$botUserID = "4xp9fdt77pncbef59f4k1qe83o";
$userID = "adWv1qPZmHdtxk7Lmqh6RtxWxS";
$resp = $driver->getBotModel()->assignBotToUser($botUserID, $userID);
if ($resp->getStatusCode() == 200) {
$assignedBot = json_decode($resp->getBody());
}
"/api/v4/bots/{bot_user_id}/icon":
get:
tags:
@ -500,41 +313,6 @@
$ref: "#/components/responses/InternalServerError"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
botUserID := "4xp9fdt77pncbef59f4k1qe83o"
data, resp := Client.GetBotIconImage(botUserID)
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$botUserID = "4xp9fdt77pncbef59f4k1qe83o";
$resp = $driver->getBotModel()->getBotIcon($botUserID);
if ($resp->getStatusCode() == 200) {
$data = json_decode($resp->getBody());
}
post:
tags:
- bots
@ -587,62 +365,6 @@
$ref: "#/components/responses/InternalServerError"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import (
"io/ioutil"
"log"
"github.com/mattermost/mattermost-server/v5/model"
)
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
data, err := ioutil.ReadFile("icon_image.svg")
if err != nil {
log.Fatal(err)
}
botUserID := "4xp9fdt77pncbef59f4k1qe83o"
ok, resp := Client.SetBotIconImage(botUserID, data)
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$botUserID = "4xp9fdt77pncbef59f4k1qe83o";
$resource = fopen("icon_image.svg", 'rb');
if ($resource === false) {
throw new \Exeption("Failure.");
}
$data = new \GuzzleHttp\Psr7\Stream($resource);
$resp = $driver->getBotModel()->setBotIcon($botUserID, [
"image" => $data,
]);
fclose($resource);
if ($resp->getStatusCode() == 200) {
$ok = json_decode($resp->getBody())->status;
}
delete:
tags:
- bots
@ -679,41 +401,6 @@
$ref: "#/components/responses/InternalServerError"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
botUserID := "4xp9fdt77pncbef59f4k1qe83o"
ok, resp := Client.DeleteBotIconImage(botUserID)
- lang: PHP
source: |
require 'vendor/autoload.php';
use \Gnello\Mattermost\Driver;
$container = new \Pimple\Container([
"driver" => [
"url" => "https://your-mattermost-url.com",
"login_id" => "email@domain.com",
"password" => "Password1",
]
]);
$driver = new Driver($container);
$driver->authenticate();
$botUserID = "4xp9fdt77pncbef59f4k1qe83o";
$resp = $driver->getBotModel()->deleteBotIcon($botUserID);
if ($resp->getStatusCode() == 200) {
$ok = json_decode($resp->getBody())->status;
}
"/api/v4/bots/{bot_user_id}/convert_to_user":
post:
tags:
@ -784,17 +471,3 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
userId := "BbaYBYDV5IDOZFiJGBSzkw1k5u"
patch := &model.UserPatch{}
patch.Email = model.NewString("test@domain.com")
patch.Username = model.NewString("testUsername")
patch.Password = model.NewString("password")
user, resp := Client.ConvertBotToUser(userId, userPatch, false)

View File

@ -22,16 +22,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetBrandImage
img, err := Client.GetBrandImage()
post:
tags:
- brand
@ -70,26 +60,6 @@
$ref: "#/components/responses/TooLarge"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
file, err := os.Open("<Your image>")
if err != nil {
return err
}
defer file.Close()
data := &bytes.Buffer{}
if _, err := io.Copy(data, file); err != nil {
return err
}
ok, resp := Client.UploadBrandImage(data.Bytes())
delete:
tags:
- brand
@ -117,13 +87,3 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// Delete brand image
resp := Client.DeleteBrandImage()

View File

@ -124,22 +124,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
channel := &model.Channel{DisplayName: <YOUR CHANNEL DISPLAYNAME>, Name: <YOUR CHANNEL NAME>, Type: <CHANNEL TYPE OPEN/PRIVATE>, TeamId: <YOUR TEAM ID>}
// CreateChannel
rchannel, resp := Client.CreateChannel(channel)
/api/v4/channels/direct:
post:
tags:
@ -176,15 +160,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// CreateDirectChannel
dm, resp := Client.CreateDirectChannel(<ID OF User1>, <ID OF User2>)
/api/v4/channels/group:
post:
tags:
@ -220,17 +195,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
userIds := []string{<ID OF User1>, <ID OF User2>, <ID OF User3> ...}
// CreateGroupChannel
rgc, resp := Client.CreateGroupChannel(userIds)
/api/v4/channels/search:
post:
tags:
@ -420,17 +384,6 @@
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
search := &model.ChannelSearch{Term: <MEMBER USERNAME>}
// SearchGroupChannels
channels, resp := Client.SearchGroupChannels(search)
"/api/v4/teams/{team_id}/channels/ids":
post:
tags:
@ -472,22 +425,6 @@
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
channelIds := []string{<ID OF CHANNEL1>, <ID OF CHANNEL2>, ...}
// GetPublicChannelsByIdsForTeam
channels, resp := Client.GetPublicChannelsByIdsForTeam(<TEAMID>, channelIds)
"/api/v4/channels/{channel_id}/timezones":
get:
tags:
@ -523,15 +460,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelStats
stats, resp := Client.GetChannelTimezones(<CHANNELID>)
"/api/v4/channels/{channel_id}":
get:
tags:
@ -562,15 +490,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannel
channel, resp := Client.GetChannel(<CHANNELID>, "")
put:
tags:
- channels
@ -632,22 +551,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
channel := &model.Channel{DisplayName: <YOUR CHANNEL NEW DISPLAYNAME>, ChannelId: <CHANNELID>, TeamId: <YOUR TEAM ID>}
// UpdateChannel
updatedChannel, resp := Client.UpdateChannel(channel)
delete:
tags:
- channels
@ -689,15 +592,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// DeleteChannel
pass, resp := Client.DeleteChannel(<CHANNELID>)
"/api/v4/channels/{channel_id}/patch":
put:
tags:
@ -757,26 +651,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
patch := &model.ChannelPatch{
Name: new(string),
DisplayName: new(string),
Header: new(string),
Purpose: new(string),
}
*patch.Name = "<SOME_NEW_NAME>"
*patch.DisplayName = "<SOME_NEW_DISPLAYNAME>"
*patch.Header = "<SOME_NEW_HEADER>"
*patch.Purpose = "<SOME_NEW_PURPOSE>"
// PatchChannel
channel, resp := Client.PatchChannel(<CHANNELID>, patch)
"/api/v4/channels/{channel_id}/privacy":
put:
tags:
@ -831,24 +705,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// Update channel's privacy to Public
updatedChannel, resp := Client.UpdateChannelPrivacy(<CHANNELID>, model.CHANNEL_OPEN)
// Update channel's privacy to Private
updatedChannel, resp := Client.UpdateChannelPrivacy(<CHANNELID>, model.CHANNEL_PRIVATE)
"/api/v4/channels/{channel_id}/restore":
post:
tags:
@ -962,15 +818,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelStats
stats, resp := Client.GetChannelStats(<CHANNELID>)
"/api/v4/channels/{channel_id}/pinned":
get:
tags:
@ -998,15 +845,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetPinnedPosts
posts, resp := Client.GetPinnedPosts(<CHANNELID>, "")
"/api/v4/teams/{team_id}/channels":
get:
tags:
@ -1056,18 +894,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetPublicChannelsForTeam
channels, resp := Client.GetPublicChannelsForTeam(<TEAMID>, 0, 100, "")
"/api/v4/teams/{team_id}/channels/private":
get:
tags:
@ -1118,18 +944,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetPrivateChannelsForTeam
channels, resp := Client.GetPrivateChannelsForTeam(<TEAMID>, 0, 100, "")
"/api/v4/teams/{team_id}/channels/deleted":
get:
tags:
@ -1326,17 +1140,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
search := &model.ChannelSearch{Term: <CHANNEL DISPLAYNAME>}
// SearchChannels
channels, resp := Client.SearchChannels(<TEAMID>, search)
"/api/v4/teams/{team_id}/channels/search_archived":
post:
tags:
@ -1395,17 +1198,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
search := &model.ChannelSearch{Term: <CHANNEL DISPLAYNAME>}
// SearchChannels
channels, resp := Client.SearchArchivedChannels(<TEAMID>, search)
"/api/v4/teams/{team_id}/channels/name/{channel_name}":
get:
tags:
@ -1448,19 +1240,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelByName
channel, resp := Client.GetChannelByName(<CHANNEL NAME>, <TEAMID>, "")
"/api/v4/teams/name/{team_name}/channels/name/{channel_name}":
get:
tags:
@ -1503,19 +1282,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelByNameForTeamName
channel, resp = Client.GetChannelByNameForTeamName(<CHANNEL NAME>, <TEAM NAME>, "")
"/api/v4/channels/{channel_id}/members":
get:
tags:
@ -1560,19 +1326,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelMembers
members, resp := Client.GetChannelMembers(th.BasicChannel.Id, 0, 60, "")
post:
tags:
- channels
@ -1615,24 +1368,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// AddChannelMember
cm, resp := Client.AddChannelMember(<CHANNEL ID>, <ID OF USER TO ADD>)
// AddChannelMemberWithRootId
cm, resp := Client.AddChannelMemberWithRootId(<CHANNEL ID>, <ID OF USER TO ADD>, <POST ROOT ID>)
"/api/v4/channels/{channel_id}/members/ids":
post:
tags:
@ -1676,17 +1411,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
usersIds := []string{<Id of User1>, <Id of User2>, ...}
// GetChannelMembersByIds
cm, resp := Client.GetChannelMembersByIds(<CHANNELID>, usersIds)
"/api/v4/channels/{channel_id}/members/{user_id}":
get:
tags:
@ -1723,15 +1447,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelMember
member, resp := Client.GetChannelMember(<CHANNELID>, <USERID>, "")
delete:
tags:
- channels
@ -1774,15 +1489,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// RemoveUserFromChannel
pass, resp := Client.RemoveUserFromChannel(<CHANNELID>, <USERID>)
"/api/v4/channels/{channel_id}/members/{user_id}/roles":
put:
tags:
@ -1831,19 +1537,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// UpdateChannelRoles
pass, resp := Client.UpdateChannelRoles(<CHANNELID>, <USERIDTOPROMOTE>, "channel_admin channel_user")
"/api/v4/channels/{channel_id}/members/{user_id}/schemeRoles":
put:
tags:
@ -1951,26 +1644,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
props := map[string]string{}
props[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION
props[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION
// UpdateChannelNotifyProps
pass, resp := Client.UpdateChannelNotifyProps(<CHANNELID>, <USERID>, props)
"/api/v4/channels/members/{user_id}/view":
post:
tags:
@ -2034,18 +1707,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
view := &model.ChannelView{
ChannelId: <CHANNELID>,
}
// ViewChannel
pass, resp := Client.ViewChannel(<USERID>, view)
"/api/v4/users/{user_id}/teams/{team_id}/channels/members":
get:
tags:
@ -2087,19 +1748,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelMembersForUser
members, resp := Client.GetChannelMembersForUser(<USERID>, <TEAMID>, "")
"/api/v4/users/{user_id}/teams/{team_id}/channels":
get:
tags:
@ -2154,19 +1802,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelsForTeamForUser
channels, resp := Client.GetChannelsForTeamForUser(<TEAMID>, <USERID>, "")
"/api/v4/users/{user_id}/channels":
get:
tags:
@ -2217,21 +1852,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v6/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
channels, response, err := Client.GetChannelsForUserWithLastDeleteAt("fc6suoon9pbbpmhrb9c967paxe", 0)
- lang: Curl
source: |
curl -X GET 'http://localhost:8065/api/v4/users/fc6suoon9pbbpmhrb9c967paxe/channels' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw'
"/api/v4/users/{user_id}/channels/{channel_id}/unread":
get:
tags:
@ -2272,19 +1892,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetChannelUnread
channelUnread, resp := Client.GetChannelUnread(<CHANNELID>, <USERID>)
"/api/v4/channels/{channel_id}/scheme":
put:
tags:
@ -2337,23 +1944,6 @@
$ref: "#/components/responses/Forbidden"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
channelID := "4xp9fdt77pncbef59f4k1qe83o"
schemeID := "qjda3stwafbgpqjaxej3k76sga"
ok, resp := UpdateChannelScheme(channelID, schemeID)
- lang: curl
source: >
curl -X PUT \
https://your-mattermost-url.com/api/v4/channels/4xp9fdt77pncbef59f4k1qe83o/scheme \
-H 'Authorization: Bearer frn8fu5rtpyc5m4xy6q3oj4yur' \
-H 'Content-Type: application/json' \
-d '{"scheme_id": "qjda3stwafbgpqjaxej3k76sga"}'
"/api/v4/channels/{channel_id}/members_minus_group_members":
get:
tags:
@ -2411,14 +2001,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: curl
source: >
curl -X GET \
'http://your-mattermost-url.com/api/v4/channels/3wyp678obid8pggjmhmhwpah1r/members_minus_group_members?group_ids=eoezijg8zffgjmch8icy5bjd1e,ugaw6wjc3tfxpcr1eq5u5k8dhe&page=0&per_page=100' \
-H 'Authorization: Bearer kno8tcdotpbx3dj1gzcbx9jrqy' \
-H 'Content-Type: application/json' \
-H 'X-Requested-With: XMLHttpRequest'
"/api/v4/channels/{channel_id}/member_counts_by_group":
get:
tags:
@ -2455,14 +2037,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: curl
source: >
curl -X GET \
'http://your-mattermost-url.com/api/v4/channels/3wyp678obid8pggjmhmhwpah1r/member_counts_by_group?include_timezones=true' \
-H 'Authorization: Bearer kno8tcdotpbx3dj1gzcbx9jrqy' \
-H 'Content-Type: application/json' \
-H 'X-Requested-With: XMLHttpRequest'
"/api/v4/channels/{channel_id}/moderations":
get:
tags:

View File

@ -48,28 +48,6 @@
$ref: "#/components/responses/Forbidden"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
newCmd := &model.Command {
TeamId: <TEAMID>,
URL: "http://nowhere.com",
Method: model.COMMAND_METHOD_POST,
Trigger: "trigger",
AutoComplete: false,
Description: "Description",
DisplayName: "Display name",
IconURL: "IconURL",
Username: "Username"
}
// CreateCommand
createdCmd, resp := Client.CreateCommand(newCmd)
get:
tags:
- commands
@ -111,22 +89,6 @@
$ref: "#/components/responses/Forbidden"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// ListCommands
// The second parameter is to set if you want only custom commands (true) or defaults commands (false)
listCommands, resp := Client.ListCommands(<TEAMID>, true)
"/api/v4/teams/{team_id}/commands/autocomplete":
get:
tags:
@ -159,16 +121,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// ListAutocompleteCommands
listCommands, resp := Client.ListAutocompleteCommands(<TEAMID>)
'/api/v4/teams/{team_id}/commands/autocomplete_suggestions':
get:
tags:
@ -208,18 +160,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: 'Go'
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// ListCommandAutocompleteSuggestions
teamID := "4xp9fdt77pncbef59f4k1qe83o"
userInput := "/jira"
listCommands, resp := Client.ListCommandAutocompleteSuggestions(userInput, teamID)
"/api/v4/commands/{command_id}":
get:
tags:
@ -255,16 +195,6 @@
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetCommand
cmd, resp := Client.GetCommand(<COMMANDID>)
put:
tags:
- commands
@ -302,24 +232,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
cmdToUpdate := &model.Command{
CreatorId: <USERID>,
TeamId: <TEAMID>,
URL: "<http://nowhere.com/change>",
Trigger: <NEWTRIGGERNAME>,
Id: <COMMANDID>,
}
// UpdateCommand
listCommands, resp := Client.UpdateCommand(cmdToUpdate)
delete:
tags:
- commands
@ -353,16 +265,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// DeleteCommand
ok, resp := Client.DeleteCommand(<COMMANDID>)
"/api/v4/commands/{command_id}/move":
put:
tags:
@ -410,16 +312,6 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// MoveCommand
ok, resp := Client.MoveCommand(<TEAMID>,<COMMANDID>)
"/api/v4/commands/{command_id}/regen_token":
put:
tags:
@ -456,16 +348,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// RegenCommandToken
newToken, resp := Client.RegenCommandToken(<COMMANDID>)
/api/v4/commands/execute:
post:
tags:

View File

@ -21,18 +21,6 @@
$ref: "#/components/responses/Forbidden"
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
exports, response := Client.ListExports()
- lang: Curl
source: |
curl 'http://localhost:8065/api/v4/exports' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw'
"/api/v4/exports/{export_name}":
get:
tags:
@ -66,26 +54,6 @@
$ref: "#/components/responses/NotFound"
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: |
import (
"os"
"github.com/mattermost/mattermost-server/v5/model"
}
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
outFile, _ := os.Create("export.zip")
n, response := Client.DownloadExport("export.zip", outFile, 0)
- lang: Curl
source: |
curl 'http://localhost:8065/api/v4/exports/export.zip' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw'
delete:
tags:
- exports
@ -116,17 +84,3 @@
$ref: "#/components/responses/Forbidden"
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
ok, response := Client.DeleteExport("export.zip")
- lang: Curl
source: |
curl -X DELETE 'http://localhost:8065/api/v4/exports/export.zip' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw'

View File

@ -83,45 +83,6 @@
$ref: "#/components/responses/TooLarge"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
file, err := os.Open("file.png")
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
defer file.Close();
buf := bytes.NewBuffer(nil)
io.Copy(buf, file)
data := buf.Bytes()
channelID := "4xp9fdt77pncbef59f4k1qe83o"
filename := "file.png"
fileUploadResponse, response := Client.UploadFile(data, channelID, filename)
- lang: Curl
source: |
curl -F 'files=@PATH/TO/LOCAL/FILE' \
-F 'channel_id=CHANNEL_ID' \
--header 'authorization: Bearer c49adc55z3f53ck7xtp8ebq1ir'
https://your-mattermost-url.com/api/v4/files
"/api/v4/files/{file_id}":
get:
tags:
@ -159,17 +120,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
fileID := "4xp9fdt77pncbef59f4k1qe83o"
data, resp := Client.GetFile(fileID)
"/api/v4/files/{file_id}/thumbnail":
get:
tags:
@ -207,17 +157,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
fileID := "4xp9fdt77pncbef59f4k1qe83o"
data, resp := Client.GetFileThumbnail(fileID)
"/api/v4/files/{file_id}/preview":
get:
tags:
@ -255,17 +194,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
fileID := "4xp9fdt77pncbef59f4k1qe83o"
data, resp := Client.GetFilePreview(fileID)
"/api/v4/files/{file_id}/link":
get:
tags:
@ -315,17 +243,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
fileID := "4xp9fdt77pncbef59f4k1qe83o"
data, resp := Client.GetFileLink(fileID)
"/api/v4/files/{file_id}/info":
get:
tags:
@ -369,17 +286,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
fileID := "4xp9fdt77pncbef59f4k1qe83o"
info, resp := Client.GetFileInfo(fileID)
"/files/{file_id}/public":
get:
tags:
@ -499,22 +405,3 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
teamID := "zWEyrTZ7GZ22aBSfoX60iWryTY"
fileInfoList, resp := Client.SearchFiles(teamID, "filename", false)
- lang: curl
source: >
curl -X POST \
https://your-mattermost-url.com/api/v4/teams/zWEyrTZ7GZ22aBSfoX60iWryTY/files/search \
-H 'Authorization: Bearer frn8fu5rtpyc5m4xy6q3oj4yur' \
-H 'Content-Type: application/json' \
-d '{"terms": "filename", "is_or_search": false}'

View File

@ -22,18 +22,3 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
imports, response := Client.ListImports()
- lang: Curl
source: |
curl 'http://localhost:8065/api/v4/imports' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw'

View File

@ -61,15 +61,9 @@ tags:
* [Mattermost Golang Driver](https://github.com/mattermost/mattermost/blob/master/server/public/model/client4.go)
#### Community-built Drivers
* [PHP Driver](https://github.com/gnello/php-mattermost-driver) - built by [@gnello](https://github.com/gnello) and [@prixone](https://github.com/prixone)
* [Python Driver](https://github.com/Vaelor/python-mattermost-driver) - built by [@Vaelor](https://github.com/Vaelor)
For other community-built drivers and API wrappers, see [our app directory](https://mattermost.com/marketplace/).
For community-built drivers and API wrappers, see [our app directory](https://mattermost.com/marketplace/).
- name: authentication
description: >
There are multiple ways to authenticate against the Mattermost API.

View File

@ -209,26 +209,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
appToUpdate := &model.OAuthApp{
Id: <APP ID>,
Name: <APP NAME>,
Description: <APP DESCRIPTION>,
IconURL: <URL TO APP ICON>,
CallbackUrls: [<CALLBACK URL1>, <CALLBACK URL2>],
Homepage: <URL TO APP HOMEPAGE>,
IsTrusted: <BOOLEAN>
}
// UpdateOAuthApp
updatedApp, resp := Client.UpdateOAuthApp(appToUpdate)
delete:
tags:
- OAuth

View File

@ -49,38 +49,6 @@
$ref: "#/components/responses/TooLarge"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: >
import (
"bytes"
"io/ioutil"
"log"
"github.com/mattermost/mattermost-server/v5/model"
)
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
tarData, err := ioutil.ReadFile("plugin.tar.gz")
if err != nil {
log.Fatal("error while reading file")
}
// Not forced
manifest, resp := Client.UploadPlugin(bytes.NewReader(tarData))
// Forced
manifest, resp := Client.UploadPluginForced(bytes.NewReader(tarData))
get:
tags:
- plugins
@ -121,15 +89,6 @@
$ref: "#/components/responses/Forbidden"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
pluginsResp, resp := Client.GetPlugins()
/api/v4/plugins/install_from_url:
post:
tags:
@ -174,23 +133,6 @@
$ref: "#/components/responses/Forbidden"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import (
"github.com/mattermost/mattermost-server/v5/model"
)
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
url := "https://mysite.com/my-plugin.tar.gz"
// Not forced
manifest, resp := Client.InstallPluginFromUrl(url, false)
// Forced
manifest, resp := Client.InstallPluginFromUrl(url, true)
"/api/v4/plugins/{plugin_id}":
delete:
tags:
@ -232,17 +174,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
pluginID := "com.mattermost.demo-plugin"
ok, resp = Client.RemovePlugin(pluginID)
"/api/v4/plugins/{plugin_id}/enable":
post:
tags:
@ -284,17 +215,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
pluginID := "com.mattermost.demo-plugin"
ok, resp = Client.EnablePlugin(pluginID)
"/api/v4/plugins/{plugin_id}/disable":
post:
tags:
@ -336,17 +256,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
pluginID := "com.mattermost.demo-plugin"
ok, resp = Client.DisablePlugin(pluginID)
/api/v4/plugins/webapp:
get:
tags:
@ -377,14 +286,6 @@
$ref: "#/components/responses/Forbidden"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
manifests, resp := Client.GetWebappPlugins()
/api/v4/plugins/statuses:
get:
tags:
@ -415,14 +316,6 @@
$ref: "#/components/responses/Forbidden"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
manifests, resp := Client.GetPluginStatuses()
/api/v4/plugins/marketplace:
post:
tags:
@ -470,19 +363,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
plugin := &model.InstallMarketplacePluginRequest{
Id: "antivirus",
}
ok, resp = Client.InstallMarketplacePlugin(plugin)
get:
tags:
- plugins
@ -548,23 +428,6 @@
$ref: "#/components/responses/Forbidden"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
filter := &model.MarketplacePluginFilter{
Page: 1,
PerPage: 10,
Filter: "antivirus",
ServerVersion: "0.1.2",
LocalOnly: true,
}
ok, resp = Client.GetMarketplacePlugins(filter)
/api/v4/plugins/marketplace/first_admin_visit:
get:
tags:

View File

@ -127,21 +127,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
client := model.NewAPIv4Client("https://your-mattermost-url.com")
client.Login("email@domain.com", "Password1")
ephemeralPost := &model.PostEphemeral{
UserID: "<ID OF THE USER THAT WOULD RECEIVE THE POST>",
Post: &model.Post{
ChannelId: "<ID OF CHANNEL>",
Message: "<YOUR MESSAGE>",
},
}
createdPost, response := client.CreatePostEphemeral(ephemeralPost)
"/api/v4/posts/{post_id}":
get:
tags:

View File

@ -25,15 +25,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
roles, resp := Client.GetAllRoles()
"/api/v4/roles/{role_id}":
get:
tags:
@ -65,14 +56,6 @@
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
role, resp := Client.GetRole(<ROLEID>, "")
"/api/v4/roles/name/{role_name}":
get:
tags:
@ -104,14 +87,6 @@
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
role, resp := Client.GetRoleByName(<ROLENAME>, "")
"/api/v4/roles/{role_id}/patch":
put:
tags:
@ -202,13 +177,3 @@
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
roleNames := []string{<NAME OF ROLE1>, <NAME OF ROLE2>, ...}
roles, resp := Client.GetRolesByNames(roleNames)

View File

@ -130,14 +130,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
scheme, resp := Client.GetScheme(<SCHEMEID>, "")
delete:
tags:
- schemes

View File

@ -45,23 +45,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
teamID := "4xp9fdt77pncbef59f4k1qe83o"
shared_channels, err := Client.GetAllSharedChannels(teamID, 0, 100)
- lang: curl
source: |
curl -X POST \
'http://your-mattermost-url.com/api/v4/sharedchannels/4xp9fdt77pncbef59f4k1qe83o' \
-H 'Authorization: Bearer kno8tcdotpbx3dj1gzcbx9jrqy'
"/api/v4/sharedchannels/remote_info/{remote_id}":
get:
tags:
@ -97,20 +80,3 @@
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
remoteID := "4xp9fdt77pncbef59f4k1qe83o"
info, err := Client.GetRemoteClusterInfo(remoteID)
- lang: curl
source: |
curl -X POST \
'http://your-mattermost-url.com/api/v4/sharedchannels/getremote/4xp9fdt77pncbef59f4k1qe83o' \
-H 'Authorization: Bearer kno8tcdotpbx3dj1gzcbx9jrqy'

View File

@ -73,19 +73,6 @@
$ref: "#/components/schemas/SystemStatusResponse"
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetPing
status, resp := Client.GetPing()
// Get server status with database and storage checks
status, resp = Client.GetPingWithServerStatus()
"/api/v4/system/notices/{teamId}":
get:
tags:
@ -137,15 +124,6 @@
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
notices, resp := Client.GetNotices(0, teamId, "mobile-android", "1.2.3", "enUS")
/api/v4/system/notices/view:
put:
tags:
@ -178,17 +156,6 @@
$ref: "#/components/schemas/StatusOK"
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
notices := []string{"id1","id2"}
resp := Client.MarkNoticesViewed(notices)
/api/v4/database/recycle:
post:
tags:
@ -211,15 +178,6 @@
$ref: "#/components/schemas/StatusOK"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
ok, resp := Client.DatabaseRecycle()
/api/v4/email/test:
post:
tags:
@ -253,25 +211,6 @@
$ref: "#/components/responses/Forbidden"
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
config := model.Config{
EmailSettings: model.EmailSettings{
SMTPServer: <SMTPServer>,
SMTPPort: <SMTPPort>,
SMTPUsername: <SMTPUsername>,
SMTPPassword: <SMTPPassword>,
},
}
// TestEmail
ok, resp := Client.TestEmail(&config)
/api/v4/site_url/test:
post:
tags:
@ -314,18 +253,6 @@
$ref: "#/components/responses/Forbidden"
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
siteURL := "https://your-new-mattermost-url.com"
// TestSiteURL
ok, resp := Client.TestSiteURL(siteUrl)
/api/v4/file/s3_test:
post:
tags:
@ -361,26 +288,6 @@
$ref: "#/components/responses/Forbidden"
"500":
$ref: "#/components/responses/InternalServerError"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
config := model.Config{
FileSettings: model.FileSettings{
DriverName: model.NewString(model.IMAGE_DRIVER_S3),
AmazonS3AccessKeyId: <AmazonS3AccessKeyId>,
AmazonS3SecretAccessKey: <AmazonS3SecretAccessKey>,
AmazonS3Bucket: <AmazonS3Bucket>,
AmazonS3Endpoint: <AmazonS3Endpoint>
},
}
// TestS3Connection
ok, resp := Client.TestS3Connection(&config)
/api/v4/config:
get:
tags:
@ -402,16 +309,6 @@
$ref: "#/components/responses/BadRequest"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetConfig
config, resp := Client.GetConfig()
put:
tags:
- system
@ -449,21 +346,6 @@
$ref: "#/components/responses/BadRequest"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetConfig
config, resp := Client.GetConfig()
config.TeamSettings.SiteName = "MyFancyName"
// UpdateConfig
updatedConfig, resp := Client.UpdateConfig(config)
/api/v4/config/reload:
post:
tags:
@ -485,16 +367,6 @@
$ref: "#/components/responses/BadRequest"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// ReloadConfig
ok, resp := Client.ReloadConfig()
/api/v4/config/client:
get:
tags:
@ -519,16 +391,6 @@
$ref: "#/components/responses/BadRequest"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetOldClientConfig
ok, resp := Client.GetOldClientConfig()
/api/v4/config/environment:
get:
tags:
@ -604,21 +466,6 @@
$ref: "#/components/responses/BadRequest"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetConfig
config, resp := Client.GetConfig()
config.TeamSettings.SiteName = "MyFancyName"
// UpdateConfig
updatedConfig, resp := Client.PatchConfig(config)
/api/v4/license:
post:
tags:
@ -659,26 +506,6 @@
$ref: "#/components/responses/Forbidden"
"413":
$ref: "#/components/responses/TooLarge"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
file, err := os.Open("<Your license file>")
if err != nil {
return err
}
defer file.Close()
data := &bytes.Buffer{}
if _, err := io.Copy(data, file); err != nil {
return err
}
ok, resp := Client.UploadLicenseFile(data.Bytes())
delete:
tags:
- system
@ -728,16 +555,6 @@
$ref: "#/components/responses/BadRequest"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetOldClientLicense
license, resp := Client.GetOldClientLicense()
/api/v4/license/renewal:
get:
tags:
@ -803,16 +620,6 @@
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// RequestTrialLicense
resp := Client.RequestTrialLicense()
/api/v4/trial-license/prev:
get:
tags:
@ -873,16 +680,6 @@
$ref: "#/components/schemas/Audit"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetAudits
audits, resp := Client.GetAudits(0, 100, "")
/api/v4/caches/invalidate:
post:
tags:
@ -906,16 +703,6 @@
$ref: "#/components/schemas/StatusOK"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// InvalidateCaches
ok, resp := Client.InvalidateCaches()
/api/v4/logs:
get:
tags:
@ -954,16 +741,6 @@
type: string
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// GetLogs
logs, resp := Client.GetLogs(0, 10)
post:
tags:
- system
@ -1006,20 +783,6 @@
type: string
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
message := make(map[string]string)
message["level"] = "ERROR"
message["message"] = "this is a test"
// PostLog
_, resp := Client.PostLog(message)
/api/v4/analytics/old:
get:
tags:
@ -1101,20 +864,6 @@
$ref: "#/components/responses/BadRequest"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
ok, resp := Client.SetServerBusy(300)
- lang: curl
source: |
curl -X POST \
'http://your-mattermost-url.com/api/v4/server_busy?seconds=3600' \
-H 'Authorization: Bearer kno8tcdotpbx3dj1gzcbx9jrqy'
get:
tags:
- system
@ -1140,22 +889,6 @@
$ref: "#/components/schemas/Server_Busy"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
// expires is a time.Time
expires, resp := Client.GetServerBusyExpires()
- lang: curl
source: |
curl -X GET \
'http://your-mattermost-url.com/api/v4/server_busy' \
-H 'Authorization: Bearer kno8tcdotpbx3dj1gzcbx9jrqy' \
-H 'Content-Type: application/json'
delete:
tags:
- system
@ -1181,20 +914,6 @@
$ref: "#/components/schemas/StatusOK"
"403":
$ref: "#/components/responses/Forbidden"
x-code-samples:
- lang: Go
source: |
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
ok, resp := Client.ClearServerBusy()
- lang: curl
source: |
curl -X DELETE \
'http://your-mattermost-url.com/api/v4/server_busy' \
-H 'Authorization: Bearer kno8tcdotpbx3dj1gzcbx9jrqy'
/api/v4/notifications/ack:
post:
tags:
@ -1498,19 +1217,6 @@
type: array
items:
$ref: "#/components/schemas/IntegrityCheckResult"
x-code-samples:
- lang: Go
source: |
import (
"net"
"net/http"
"github.com/mattermost/mattermost-server/v5/model"
)
Client := model.NewAPIv4SocketClient(socketPath)
ok, resp := Client.CheckIntegrity()
/api/v4/system/support_packet:
get:
tags:

File diff suppressed because it is too large Load Diff

View File

@ -52,29 +52,6 @@
$ref: "#/components/responses/TooLarge"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
us := &model.UploadSession{
ChannelId: "4i6jn8r483nnuqnibnmgz8jo4o",
Filename: "file.png",
FileSize: 512000,
}
us, response := Client.CreateUpload(us)
- lang: Curl
source: |
curl 'http://localhost:8065/api/v4/uploads' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw' \
-H 'Content-Type: application/json' \
--data-binary '{"channel_id": "4i6jn8r483nnuqnibnmgz8jo4o", "filename": "test.png", "file_size": 512000}'
"/api/v4/uploads/{upload_id}":
get:
tags:
@ -104,21 +81,6 @@
$ref: "#/components/responses/NotFound"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: >
import "github.com/mattermost/mattermost-server/v5/model"
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
us, response := Client.GetUpload("nuyrh9ymridqmenof7exe3a6aw")
- lang: Curl
source: |
curl 'http://localhost:8065/api/v4/uploads/nuyrh9ymridqmenof7exe3a6aw' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw'
post:
tags:
- uploads
@ -165,31 +127,3 @@
$ref: "#/components/responses/TooLarge"
"501":
$ref: "#/components/responses/NotImplemented"
x-code-samples:
- lang: Go
source: >
import (
"os"
"github.com/mattermost/mattermost-server/v5/model"
)
Client := model.NewAPIv4Client("https://your-mattermost-url.com")
Client.Login("email@domain.com", "Password1")
file, err := os.Open("file.png")
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return
}
info, err := Client.UploadData(us, file)
- lang: Curl
source: |
# Binary file content in request's body
curl -X POST 'http://localhost:8065/api/v4/uploads/qyxbzmprrjbdpdaprsxm98m6qe' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw' --data-binary @file.png
# multipart/form-data upload
curl 'http://localhost:8065/api/v4/uploads/qyxbzmprrjbdpdaprsxm98m6qe' \
-H 'Authorization: Bearer 9kg8nqrnxprd9jbykqeg4r51hw' -F data=@file.png

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,493 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model_test
import (
"context"
"fmt"
"log"
"os"
"strings"
"github.com/mattermost/mattermost/server/public/model"
)
func ExampleClient4_CreateChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channel, _, err := client.CreateChannel(context.Background(), &model.Channel{
Name: "channel_name",
DisplayName: "Channel Name",
Type: model.ChannelTypeOpen,
TeamId: "team_id",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created channel with id %s\n", channel.Id)
}
func ExampleClient4_CreateDirectChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
userID1 := "user_id_1"
userID2 := "user_id_2"
channel, _, err := client.CreateDirectChannel(context.Background(), userID1, userID2)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created direct message channel with id %s for users %s and %s\n", channel.Id, userID1, userID2)
}
func ExampleClient4_CreateGroupChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
userIDs := []string{"user_id_1", "user_id_2", "user_id_3"}
channel, _, err := client.CreateGroupChannel(context.Background(), userIDs)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created group message channel with id %s for users %s, %s and %s\n", channel.Id, userIDs[0], userIDs[1], userIDs[2])
}
func ExampleClient4_SearchGroupChannels() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channels, _, err := client.SearchGroupChannels(context.Background(), &model.ChannelSearch{
Term: "member username",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d channels\n", len(channels))
}
func ExampleClient4_GetPublicChannelsByIdsForTeam() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
teamId := "team_id"
channelIds := []string{"channel_id_1", "channel_id_2"}
channels, _, err := client.GetPublicChannelsByIdsForTeam(context.Background(), teamId, channelIds)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d channels\n", len(channels))
}
func ExampleClient4_GetChannelMembersTimezones() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
memberTimezones, _, err := client.GetChannelMembersTimezones(context.Background(), channelId)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d timezones used by members of the channel %s\n", len(memberTimezones), channelId)
}
func ExampleClient4_GetChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
etag := ""
channel, _, err := client.GetChannel(context.Background(), channelId, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found channel with name %s\n", channel.Name)
}
func ExampleClient4_UpdateChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channel, _, err := client.UpdateChannel(context.Background(), &model.Channel{
Id: "channel_id",
TeamId: "team_id",
Name: "name",
DisplayName: "Display Name",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Channel %s updated at %d\n", channel.Id, channel.UpdateAt)
}
func ExampleClient4_DeleteChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
_, err := client.DeleteChannel(context.Background(), channelId)
if err != nil {
log.Fatal(err)
}
}
func ExampleClient4_PatchChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
patch := &model.ChannelPatch{
Name: model.NewString("new_name"),
DisplayName: model.NewString("New Display Name"),
Header: model.NewString("New header"),
Purpose: model.NewString("New purpose"),
}
_, _, err := client.PatchChannel(context.Background(), channelId, patch)
if err != nil {
log.Fatal(err)
}
}
func ExampleClient4_UpdateChannelPrivacy() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
_, _, err := client.UpdateChannelPrivacy(context.Background(), channelId, model.ChannelTypeOpen)
if err != nil {
log.Fatal(err)
}
_, _, err = client.UpdateChannelPrivacy(context.Background(), channelId, model.ChannelTypePrivate)
if err != nil {
log.Fatal(err)
}
}
func ExampleClient4_GetChannelStats() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
etag := ""
excludeFilesCount := true
stats, _, err := client.GetChannelStats(context.Background(), channelId, etag, excludeFilesCount)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d members and %d guests in channel %s\n", stats.MemberCount, stats.GuestCount, channelId)
}
func ExampleClient4_GetPinnedPosts() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
etag := ""
posts, _, err := client.GetPinnedPosts(context.Background(), channelId, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d pinned posts for channel %s\n", len(posts.Posts), channelId)
}
func ExampleClient4_GetPublicChannelsForTeam() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
teamId := "team_id"
page := 0
perPage := 100
etag := ""
channels, _, err := client.GetPublicChannelsForTeam(context.Background(), teamId, page, perPage, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d public channels for team %s\n", len(channels), teamId)
}
func ExampleClient4_GetPrivateChannelsForTeam() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
teamId := "team_id"
page := 0
perPage := 100
etag := ""
channels, _, err := client.GetPrivateChannelsForTeam(context.Background(), teamId, page, perPage, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d private channels for team %s\n", len(channels), teamId)
}
func ExampleClient4_SearchChannels() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
teamId := "team_id"
searchTerm := "search"
channels, _, err := client.SearchChannels(context.Background(), teamId, &model.ChannelSearch{
Term: searchTerm,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d channels on team %s matching term '%s'\n", len(channels), teamId, searchTerm)
}
func ExampleClient4_SearchArchivedChannels() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
teamId := "team_id"
searchTerm := "search"
channels, _, err := client.SearchArchivedChannels(context.Background(), teamId, &model.ChannelSearch{
Term: searchTerm,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d archived channels on team %s matching term '%s'\n", len(channels), teamId, searchTerm)
}
func ExampleClient4_GetChannelByName() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelName := "channel_name"
teamId := "team_id"
etag := ""
channel, _, err := client.GetChannelByName(context.Background(), channelName, teamId, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found channel %s with name %s\n", channel.Id, channel.Name)
}
func ExampleClient4_GetChannelByNameForTeamName() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelName := "channel_name"
teamName := "team_name"
etag := ""
channel, _, err := client.GetChannelByNameForTeamName(context.Background(), channelName, teamName, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found channel %s with name %s\n", channel.Id, channel.Name)
}
func ExampleClient4_GetChannelMembers() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
page := 0
perPage := 60
etag := ""
members, _, err := client.GetChannelMembers(context.Background(), channelId, page, perPage, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d channel members for channel %s\n", len(members), channelId)
}
func ExampleClient4_AddChannelMember() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
userId := "user_id"
cm, _, err := client.AddChannelMember(context.Background(), channelId, userId)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Added user %s to channel %s with roles %s\n", userId, channelId, cm.Roles)
postRootId := "post_root_id"
cm, _, err = client.AddChannelMemberWithRootId(context.Background(), channelId, userId, postRootId)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Added user %s to channel %s with roles %s using post %s\n", userId, channelId, cm.Roles, postRootId)
}
func ExampleClient4_GetChannelMembersByIds() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
usersIds := []string{"user_id_1", "user_id_2"}
members, _, err := client.GetChannelMembersByIds(context.Background(), channelId, usersIds)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d channel members for channel %s\n", len(members), channelId)
}
func ExampleClient4_GetChannelMember() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
userId := "user_id"
etag := ""
member, _, err := client.GetChannelMember(context.Background(), channelId, userId, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found channel member for user %s in channel %s having roles %s\n", userId, channelId, member.Roles)
}
func ExampleClient4_RemoveUserFromChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
userId := "user_id"
_, err := client.RemoveUserFromChannel(context.Background(), channelId, userId)
if err != nil {
log.Fatal(err)
}
}
func ExampleClient4_UpdateChannelRoles() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
userId := "user_id"
roles := []string{"channel_admin", "channel_user"}
_, err := client.UpdateChannelRoles(context.Background(), channelId, userId, strings.Join(roles, " "))
if err != nil {
log.Fatal(err)
}
}
func ExampleClient4_UpdateChannelNotifyProps() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
userId := "user_id"
props := map[string]string{
model.DesktopNotifyProp: model.ChannelNotifyMention,
model.MarkUnreadNotifyProp: model.ChannelMarkUnreadMention,
}
_, err := client.UpdateChannelNotifyProps(context.Background(), channelId, userId, props)
if err != nil {
log.Fatal(err)
}
}
func ExampleClient4_ViewChannel() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
prevChannelId := "prev_channel_id"
userId := "user_id"
_, _, err := client.ViewChannel(context.Background(), userId, &model.ChannelView{
ChannelId: channelId,
PrevChannelId: prevChannelId,
CollapsedThreadsSupported: true,
})
if err != nil {
log.Fatal(err)
}
}
func ExampleClient4_GetChannelMembersForUser() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
userId := "user_id"
teamId := "team_id"
etag := ""
members, _, err := client.GetChannelMembersForUser(context.Background(), userId, teamId, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d channel members for user %s on team %s\n", len(members), userId, teamId)
}
func ExampleClient4_GetChannelsForTeamForUser() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
userId := "user_id"
teamId := "team_id"
includeDeleted := false
etag := ""
channels, _, err := client.GetChannelsForTeamForUser(context.Background(), teamId, userId, includeDeleted, etag)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d channels for user %s on team %s\n", len(channels), userId, teamId)
}
func ExampleClient4_GetChannelsForUserWithLastDeleteAt() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
userId := "user_id"
lastDeleteAt := 0
channels, _, err := client.GetChannelsForUserWithLastDeleteAt(context.Background(), userId, lastDeleteAt)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d channels for user %s, with last delete at %d\n", len(channels), userId, lastDeleteAt)
}
func ExampleClient4_GetChannelUnread() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelId := "channel_id"
userId := "user_id"
channelUnread, _, err := client.GetChannelUnread(context.Background(), channelId, userId)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d unread messages with %d mentions for user %s in channel %s\n", channelUnread.MentionCount, channelUnread.MentionCount, userId, channelId)
}
func ExampleClient4_UpdateChannelScheme() {
client := model.NewAPIv4Client(os.Getenv("MM_SERVICESETTINGS_SITEURL"))
client.SetToken(os.Getenv("MM_AUTHTOKEN"))
channelID := "channel_id"
schemeID := "scheme_id"
_, err := client.UpdateChannelScheme(context.Background(), channelID, schemeID)
if err != nil {
log.Fatal(err)
}
}