Pluvo Developers Docs


Code Docs


Back to website: www.pluvo.com

Request data introduction

You can do a GraphQL request to the Pluvo API just the same as an REST API. Some languages also have a library you can use to make GraphQL even easier. You can also find some more information here https://graphql.org/graphql-js/graphql-clients/.

The objects all have a ref field. This ref field is used to run queries or mutation for objects. We generate an uuid4 ref for each object when a ref is not given on creation. It is also possible to pass a custom ref (like your own id for the object), then you use your own ref for queries and mutations. Make sure this ref is unique in your organisation for its object type.

GraphQL endpointhttps://[organisation-name].pluvo.com/graphql/ Note: The trailing slash at the end of the URL is essential

Node.js Example

For this example we use the npm package axios

const axios = require('axios').default;

// GraphQL request url
const graphqlUrl = 'https://[organisation-name].pluvo.com/graphql/';

// GraphQL query to get user
const GET_USER = `
    query user($ref: String) {
        user(ref: $ref) {
            ref
            name
            email
            isActive
        }
    }
`;

// Pass access token in Authorization header and set Content-Type
const requestConfig = {
    headers: {
        Authorization: `Bearer ${access_token}`,
        'Content-Type': 'application/x-www-form-urlencoded',
    },
};

const userRef = '[user-external-reference]';

const requestData = {
    query: GET_USER,
    variables: { ref: userRef },
};

axios
    .post(graphqlUrl, requestData, requestConfig)
    .then((response) => {
        const content = response.data;

        if (content.errors) {
            const error = content.errors[0];

            // When error is an Auth error we throw RefreshAuthError
            if (error.extensions.code.indexOf('Auth') !== -1) {
                console.error('We got an authentication error', content.errors);
            } else {
                console.error('We got an request error', content.errors[0].message);
            }
        }

        console.log('Got User', content.data.user);
    })
    .catch((error) => {
        console.error('Got an error response from the API', error.message);
    });