2021-03-24 07:10:26 +03:00
import * as React from "react" ;
import * as Constants from "~/common/constants" ;
import * as System from "~/components/system" ;
import CodeBlock from "~/components/system/CodeBlock" ;
import { css } from "@emotion/react" ;
2021-03-25 07:28:14 +03:00
const EXAMPLE _CODE _JS = ( key , slateId ) => {
2021-03-30 04:19:36 +03:00
return ` const SLATE_ID = " ${ slateId } "
2021-03-24 07:10:26 +03:00
const slateResponseData = getSlateById ( SLATE _ID ) ;
const slate = slateResponseData . data ;
slate . data . objects [ 0 ] . title = "Julie Was Here."
const response = await fetch ( 'https://slate.host/api/v1/update-slate' , {
method : 'POST' ,
headers : {
'Content-Type' : 'application/json' ,
Authorization : 'Basic ${key}' ,
} ,
body : JSON . stringify ( { data : slate } )
} ) ;
const json = await response . json ( ) ;
console . log ( json ) ; ` ;
} ;
2021-03-30 04:19:36 +03:00
const EXAMPLE _CODE _PY = ( key , slateId ) =>
` headers = {
"content-type" : "application/json" ,
"Authorization" : "Basic ${key}" ,
}
json = { "id" : "${slateId}" }
get _slate = requests . post (
"https://slate.host/api/v1/get-slate" , headers = headers , json = json
)
get _slate _response = get _slate . json ( )
slate = get _slate _response [ "slate" ]
# change a field in the slate response
slate [ "data" ] [ "objects" ] [ 0 ] [ "title" ] = "i changed the title"
url = "https://slate.host/api/v1/update-slate"
updated _data = { "data" : slate }
2021-03-24 07:10:26 +03:00
2021-03-30 04:19:36 +03:00
update _slate = requests . post ( url , headers = headers , json = updated _data ) ` ;
export default class APIDocsUpdateSlate extends React . Component {
render ( ) {
let language = this . props . language ;
let key = this . props . APIKey ;
let slateId = this . props . slateId ;
let code = {
javascript : EXAMPLE _CODE _JS ( key , slateId ) ,
python : EXAMPLE _CODE _PY ( key , slateId ) ,
} ;
2021-03-24 07:10:26 +03:00
return (
< React . Fragment >
< System . DescriptionGroup
2021-03-30 04:19:36 +03:00
style = { { maxWidth : 640 , marginTop : 64 } }
2021-03-24 07:10:26 +03:00
label = "Update slate by ID"
2021-03-30 04:19:36 +03:00
description = "This API endpoint allows you to modify a slate by saving the response from get-slate, modifying it, and sending it back. Be VERY careful modifying the data field of the JSON because it allows for full customization. If you change the wrong fields, it will break you slate when the database JSONB is updated. As a rule of thumb, if a field looks like something Slate would generate (keys, hashes, id's), don't change it."
2021-03-24 07:10:26 +03:00
/ >
< CodeBlock
2021-03-30 04:19:36 +03:00
children = { code }
style = { { maxWidth : "820px" } }
2021-03-24 07:10:26 +03:00
language = { language }
2021-03-25 07:28:14 +03:00
title = "Update slate by ID"
2021-03-30 04:19:36 +03:00
multiLang = "true"
onLanguageChange = { this . props . onLanguageChange }
2021-03-24 07:10:26 +03:00
/ >
< / R e a c t . F r a g m e n t >
) ;
}
}