Criando um contrato
Para criar um contrato, é necessário utilizar a mutation Contract_createContract
.
Criação com arquivo
TIP
Para uma explicação detalhada sobre como fazer upload de arquivos via GraphQL, incluindo melhores práticas e tratamento de erros, consulte nosso Guia de Upload de Arquivos com GraphQL.
Para enviar o arquivo, é necessário utilizar o FormData
do JavaScript ou alguma biblioteca que faça o envio de arquivos.
É necessário passar o header Apollo-Require-Preflight
com o valor true
para que a requisição seja feita com sucesso.
Atenção: o arquivo enviado deve ser um arquivo do tipo .pdf
.
graphql
mutation CreateContract($file: Upload) {
Contract_createContract(input: {
file: $file
}) {
__typename
... on Contract_CreateContract_Success {
contract {
id
slug
value
currency
effectiveDate
expirationDate
isFormAnswered
type
requestingArea
statusId
status {
id
label
statusCategoryId
}
participants {
role
user {
id
name
area
email
jobTitle
}
}
file {
id
fileName
fileExtension
size
contractId
type
contractSlug
}
amendments {
id
slug
}
kind
parent {
id
slug
}
customFields {
id
label
type
value
children {
id
label
type
value
}
}
}
}
}
}
js
async function createContract(file) {
const formData = new FormData();
formData.append(
'operations',
JSON.stringify({
variables: {
file: null
},
query: `
mutation CreateContract($file: Upload) {
Contract_createContract(input: {
file: $file
}) {
__typename
... on Contract_CreateContract_Success {
contract {
id
slug
value
currency
effectiveDate
expirationDate
isFormAnswered
type
requestingArea
statusId
status {
id
label
statusCategoryId
}
participants {
role
user {
id
name
area
email
jobTitle
}
}
file {
id
fileName
fileExtension
size
contractId
type
contractSlug
}
amendments {
id
slug
}
kind
parent {
id
slug
}
customFields {
id
label
type
value
children {
id
label
type
value
}
}
}
}
}
}
`
})
);
const map = `["variables.file"]`;
formData.append('map', map);
formData.append('0', file);
const response = await fetch('https://core-api.linte.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Apollo-Require-Preflight': 'true',
'key': '<seu-token>'
},
body: formData
});
const result = await response.json();
console.log(result);
}
python
import requests
def create_contract(file_path):
# Preparar o arquivo
files = {
'0': ('contract.pdf', open(file_path, 'rb'), 'application/pdf')
}
# Preparar a operação GraphQL
operations = {
'variables': {
'file': None
},
'query': '''
mutation CreateContract($file: Upload) {
Contract_createContract(input: {
file: $file
}) {
__typename
... on Contract_CreateContract_Success {
contract {
id
slug
value
currency
effectiveDate
expirationDate
isFormAnswered
type
requestingArea
statusId
status {
id
label
statusCategoryId
}
participants {
role
user {
id
name
area
email
jobTitle
}
}
file {
id
fileName
fileExtension
size
contractId
type
contractSlug
}
amendments {
id
slug
}
kind
parent {
id
slug
}
customFields {
id
label
type
value
children {
id
label
type
value
}
}
}
}
}
}
'''
}
# Preparar o mapeamento
map = {
'0': ['variables.file']
}
# Enviar a requisição
response = requests.post(
'https://core-api.linte.com/graphql',
headers={
'Content-Type': 'application/json',
'Apollo-Require-Preflight': 'true',
'key': '<seu-token>'
},
data={
'operations': json.dumps(operations),
'map': json.dumps(map)
},
files=files
)
print(response.json())
if __name__ == '__main__':
create_contract('caminho/para/seu/arquivo.pdf')
Criação sem arquivo
Para criar um contrato sem anexar um arquivo, basta enviar a mutation sem o campo file
.
graphql
mutation CreateContract {
Contract_createContract {
__typename
... on Contract_CreateContract_Success {
contract {
id
slug
value
currency
effectiveDate
expirationDate
isFormAnswered
type
requestingArea
statusId
status {
id
label
statusCategoryId
}
participants {
role
user {
id
name
area
email
jobTitle
}
}
file {
id
fileName
fileExtension
size
contractId
type
contractSlug
}
amendments {
id
slug
}
kind
parent {
id
slug
}
customFields {
id
label
type
value
children {
id
label
type
value
}
}
}
}
}
}
js
async function createContractWithoutFile() {
const response = await fetch('https://core-api.linte.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Apollo-Require-Preflight': 'true',
'key': '<seu-token>'
},
body: JSON.stringify({
query: `
mutation CreateContract {
Contract_createContract {
__typename
... on Contract_CreateContract_Success {
contract {
id
slug
value
currency
effectiveDate
expirationDate
isFormAnswered
type
requestingArea
statusId
status {
id
label
statusCategoryId
}
participants {
role
user {
id
name
area
email
jobTitle
}
}
file {
id
fileName
fileExtension
size
contractId
type
contractSlug
}
amendments {
id
slug
}
kind
parent {
id
slug
}
customFields {
id
label
type
value
children {
id
label
type
value
}
}
}
}
}
}
`
})
});
const result = await response.json();
console.log(result);
}
createContractWithoutFile();
python
import requests
def create_contract_without_file():
response = requests.post(
'https://core-api.linte.com/graphql',
headers={
'Content-Type': 'application/json',
'Apollo-Require-Preflight': 'true',
'key': '<seu-token>'
},
json={
'query': '''
mutation CreateContract {
Contract_createContract {
__typename
... on Contract_CreateContract_Success {
contract {
id
slug
value
currency
effectiveDate
expirationDate
isFormAnswered
type
requestingArea
statusId
status {
id
label
statusCategoryId
}
participants {
role
user {
id
name
area
email
jobTitle
}
}
file {
id
fileName
fileExtension
size
contractId
type
contractSlug
}
amendments {
id
slug
}
kind
parent {
id
slug
}
customFields {
id
label
type
value
children {
id
label
type
value
}
}
}
}
}
}
'''
}
)
print(response.json())
if __name__ == '__main__':
create_contract_without_file()