Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-i-me committed Apr 20, 2021
1 parent 88fe884 commit ee9146d
Show file tree
Hide file tree
Showing 13,197 changed files with 1,295,163 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions 8136/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PIPEFY_TOKEN=
PIPE_ID=
3 changes: 3 additions & 0 deletions 8136/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules

.env
329 changes: 329 additions & 0 deletions 8136/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,329 @@
# Integration Pipefy API

### Docs Pipefy API
- https://developers.pipefy.com/reference#what-is-graphql
- https://api-docs.pipefy.com/reference/overview/Card/
- https://pipefypipe.docs.apiary.io/#reference/0/list-pipes
- https://app.pipefy.com/graphiql

<br>

# Getting Started

```bash
cd Chore/8136
```
### Install dependencies

```bash
yarn
```

### Add environments
### File .env

```env
PIPEFY_TOKEN=<PIPEFY-TOKEN-HERE>
PIPE_ID=<PIPE-ID-HERE>
```

### To execute

- Commands

```bash
yarn get:startFormFields #list start form fields

yarn list:cards #list all cards

yarn show:card #show a card

yarn create:card #create a card

yarn update:card #update a card

yarn delete:card #delete a card
```

<br><br>

# List Fields Start Form

### To actually start, we need to get the fields from the initial form
- It is done as follows

<br>

```js
require('dotenv/config');
const { GraphQLClient, gql } = require('graphql-request');

const main = async () => {
const endpoint = 'https://app.pipefy.com/queries';

const graphQLClient = new GraphQLClient(endpoint);

graphQLClient.setHeader('Content-Type', 'application/json')
graphQLClient.setHeader('Authorization', `Bearer ${process.env.PIPEFY_TOKEN}`)

const query = gql`
query GetPipe($pipeId: ID!) {
pipe(id: $pipeId) {
id
name
start_form_fields {
id
internal_id
type
required
editable
}
}
}
`

const response = await graphQLClient.request(query, { pipeId: process.env.PIPE_ID })
console.log(JSON.stringify(response))
}

main().catch(err => console.log(err))
```

<br>

# CRUD
- After obtaining the form fields, we can make a crud
- Below I demonstrate how to perform a CRUD operation

<br>

# List cards

```js
require('dotenv/config');
const { GraphQLClient, gql } = require('graphql-request');

const main = async () => {
const endpoint = 'https://app.pipefy.com/queries';

const graphQLClient = new GraphQLClient(endpoint);

graphQLClient.setHeader('Content-Type', 'application/json')
graphQLClient.setHeader('Authorization', `Bearer ${process.env.PIPEFY_TOKEN}`)

const query = gql`
query ListCards($pipeId: ID!) {
cards(pipe_id: $pipeId) {
edges {
node {
id
title
done
due_date
url
labels { name }
assignees { id }
comments { text }
current_phase { name }
fields {
name
value
field {
id
type
description
}
}
phases_history {
phase { name }
firstTimeIn
lastTimeOut
}
}
}
}
}
`

const response = await graphQLClient.request(query, { pipeId: process.env.PIPE_ID })
console.log(JSON.stringify(response))
}

main().catch((err) => console.log(err));
```

<br>

# Show card

```js
require('dotenv/config');
const { GraphQLClient, gql } = require('graphql-request');

const main = async () => {
const endpoint = 'https://app.pipefy.com/queries';

const graphQLClient = new GraphQLClient(endpoint);

graphQLClient.setHeader('Content-Type', 'application/json')
graphQLClient.setHeader('Authorization', `Bearer ${process.env.PIPEFY_TOKEN}`)

const query = gql`
query ShowCard($cardId: ID!) {
card(id: $cardId) {
id
url
title
done
current_phase { name }
labels { name }
fields {
name
value
field {
id
type
description
}
}
createdBy { created_at }
}
}
`

const response = await graphQLClient.request(query, { cardId: 415998599 })
console.log(JSON.stringify(response))
}

main().catch((err) => console.log(err));
```

<br>

# Create a card

```js
require('dotenv/config');
const { GraphQLClient, gql } = require('graphql-request');

const fields = {
nome_do_requisitante: 'John Doe',
email_do_requisitante: '[email protected]',
what_s_the_bug: 'BUG Do John DOE'
}

const data = [
{field_id: Object.keys(fields)[0], field_value: fields.nome_do_requisitante},
{field_id: Object.keys(fields)[1], field_value: fields.email_do_requisitante},
{field_id: Object.keys(fields)[2], field_value: fields.what_s_the_bug}
]

const main = async () => {
const endpoint = 'https://app.pipefy.com/queries';

const graphQLClient = new GraphQLClient(endpoint);

graphQLClient.setHeader('Content-Type', 'application/json')
graphQLClient.setHeader('Authorization', `Bearer ${process.env.PIPEFY_TOKEN}`)

const mutation = gql`
mutation CreateCard($pipeId: ID!, $fieldsAttributes: [FieldValueInput]!) {
createCard(
input: {
pipe_id: $pipeId
fields_attributes: $fieldsAttributes
}
)
{
card { id }
}
}
`

const response = await graphQLClient.request(mutation, { pipeId: process.env.PIPE_ID, fieldsAttributes: data });
console.log(JSON.stringify(response));
}

main().catch((err) => console.log(err));
```

<br>

# Update a Card
- It is only possible to update a field if the `editable` property is true.

<br>

```js
require('dotenv/config');
const { GraphQLClient, gql } = require('graphql-request');

const main = async () => {
const endpoint = 'https://app.pipefy.com/queries';

const graphQLClient = new GraphQLClient(endpoint);

graphQLClient.setHeader('Content-Type', 'application/json')
graphQLClient.setHeader('Authorization', `Bearer ${process.env.PIPEFY_TOKEN}`)

const mutation = gql`
mutation UpdateCard($cardId: ID!) {
updateCard(input: {
id: $cardId
title: "Atualizei esse CARA"
})
{
card { id }
}
updateFieldsValues(input: {
nodeId: $cardId
values: [{ fieldId: "email_do_requisitante", value: "[email protected]" }]
})
{
success
}
}
`

const response = await graphQLClient.request(mutation, { cardId: 416284084 })
console.log(JSON.stringify(response))
}

main().catch((err) => console.log(err));
```

<br>

# Delete a Card

```js
require('dotenv/config');
const { GraphQLClient, gql } = require('graphql-request');

const main = async () => {
const endpoint = 'https://app.pipefy.com/queries';

const graphQLClient = new GraphQLClient(endpoint);

graphQLClient.setHeader('Content-Type', 'application/json')
graphQLClient.setHeader('Authorization', `Bearer ${process.env.PIPEFY_TOKEN}`)

const mutation = gql`
mutation DeleteCard($cardId: ID!) {
deleteCard(input: {
id: $cardId
})
{
success
}
}
`

const response = await graphQLClient.request(mutation, { cardId: 416543002 });
console.log(JSON.stringify(response));
}

main().catch((err) => console.log(err));
```

[Back to the index](..)
36 changes: 36 additions & 0 deletions 8136/docs/DeleteCard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Delete a Card

```js
require('dotenv/config');
const { GraphQLClient, gql } = require('graphql-request');

const main = async () => {
const endpoint = 'https://app.pipefy.com/queries';

const graphQLClient = new GraphQLClient(endpoint);

graphQLClient.setHeader('Content-Type', 'application/json')
graphQLClient.setHeader('Authorization', `Bearer ${process.env.PIPEFY_TOKEN}`)

const mutation = gql`
mutation DeleteCard($cardId: ID!) {
deleteCard(input: {
id: $cardId
})
{
success
}
}
`

const response = await graphQLClient.request(mutation, { cardId: 416543002 });
console.log(JSON.stringify(response));
}

main().catch((err) => console.log(err));
```

[Back to the index](..)

questions
- can you recover deleted contracts?
Loading

0 comments on commit ee9146d

Please sign in to comment.