2021-04-21 03:14:43 +03:00
import * as React from "react" ;
import * as System from "~/components/system" ;
import CodeBlock from "~/components/system/CodeBlock" ;
const EXAMPLE _CODE _JS = (
key ,
slateId
2021-04-23 08:18:46 +03:00
) => ` const response = await fetch('https://slate.host/api/v2/get-collection', {
2021-04-21 03:14:43 +03:00
method : 'POST' ,
headers : {
'Content-Type' : 'application/json' ,
2021-07-31 01:00:06 +03:00
Authorization : '${key}' ,
2021-04-21 03:14:43 +03:00
} ,
body : JSON . stringify ( { data : {
2021-04-23 08:18:46 +03:00
id : '${slateId}' // collection ID
2021-04-21 03:14:43 +03:00
} } )
} ) ;
if ( ! response ) {
console . log ( "No response" ) ;
2021-05-26 23:05:13 +03:00
return ;
}
2021-04-21 03:14:43 +03:00
const json = await response . json ( ) ;
if ( json . error ) {
2021-05-27 05:33:19 +03:00
console . log ( json ) ;
2021-04-21 03:14:43 +03:00
} else {
2021-04-23 08:18:46 +03:00
const collection = json . collection ;
2021-04-21 03:14:43 +03:00
} ` ;
const EXAMPLE _CODE _PY = ( key , slateId ) => ` import requests
import json as JSON
2021-04-23 08:18:46 +03:00
url = 'https://slate.host/api/v2/get-collection'
2021-04-21 03:14:43 +03:00
headers = {
'content-type' : 'application/json' ,
2021-07-31 01:00:06 +03:00
'Authorization' : '${key}'
2021-04-21 03:14:43 +03:00
}
json = {
"data" : {
2021-04-23 08:18:46 +03:00
"id" : "${slateId}" # collection ID
2021-04-21 03:14:43 +03:00
}
}
r = requests . post ( url , headers = headers , json = json ) ` ;
2021-04-23 08:18:46 +03:00
export default class APIDocsGetCollection extends React . Component {
2021-04-21 03:14:43 +03:00
render ( ) {
let APIKey = this . props . APIKey ;
let slateId = this . props . slateId ;
let language = this . props . language ;
let code = {
javascript : EXAMPLE _CODE _JS ( APIKey , slateId ) ,
python : EXAMPLE _CODE _PY ( APIKey , slateId ) ,
} ;
return (
< React . Fragment >
< System . DescriptionGroup
2021-07-13 22:08:56 +03:00
style = { { maxWidth : 640 , marginTop : 48 , ... this . props . style } }
2021-04-23 08:18:46 +03:00
label = "Get collection by ID"
description = "This API request will return a specific collection. You can save the response locally and send this JSON back to our API server using the route /api/v2/update-collection to update your collection."
2021-04-21 03:14:43 +03:00
/ >
< CodeBlock
children = { code }
style = { { maxWidth : "820px" } }
language = { language }
2021-04-23 08:18:46 +03:00
title = "Get collection by ID"
2021-04-21 03:14:43 +03:00
onLanguageChange = { this . props . onLanguageChange }
multiLang = "true"
/ >
< / R e a c t . F r a g m e n t >
) ;
}
}