A node.js and browser compatible JS SDK for the procore API.
yarn add @procore/js-sdk
We recommend installing the package with yarn
import 'isomorphic-fetch';
import { client, oauth, refresher, me, projects, images } from '@procore/js-sdk';
const token = document.head.querySelector('value=auth_token').getAttribute('content');
const authorizer = oauth(token);
const refreshToken = token => fetch(
'/oauth/procore/refresh',
{ method: 'POST', headers: { 'Authorization': `Bearer ${token}` } }
);
const procore = client(
refresher(authorizer, refreshToken)
);
Promise.all([
procore.get(me()),
procore.get(projects({ company_id: 2 })),
procore.get(images({ action: 'most_recent' }))
])
.then(onSuccess);
When creating an app, register the redirect URI as your app's root URL. E.g. https://example.com
import 'isomorphic-fetch';
import qs from 'qs';
import { client, oauth, implicit, me, projects, images } from '@procore/js-sdk';
const clientId = document.head.querySelector('value=client_id').getAttribute('content');
const redirectUri = document.head.querySelector('value=redirect_uri').getAttribute('content');
const accessToken = qs.parse(window.location).access_token;
if ( !accessToken ) {
window.location = implicit({ id: clientId, uri: redirectUri });
}
const procore = client(oauth(accessToken));
Promise.all([
procore.get(me()),
procore.get(projects({ company_id: 2 })),
procore.get(images({ action: 'most_recent' }))
])
})
.then(onSuccess);
A single API response contains the response body (JSON parsed), original request, and complete response. isomorphic-fetch is the underlying http library, so both the request and response follow its specification. See docs for more details.
procore
.get(projects({ company_id: 1 }))
.then({ body, response, request } => {
console.log(body[0].name); // ACME Construction LLC.
console.log(response.headers.get('Total')) // 865 (Total records for the resource)
});
yarn test
node-procore-endpoints
generates interfaces and endpoint functions for improved developer experience. See the project for more details.
interface DirectCosts {
action: string;
qs?: any;
id?: number;
project_id: number;
}
function directCosts({ action, qs, id, project_id }: DirectCosts): any {
return {
base: '/vapid/projects/{project_id}/direct_costs',
action,
params: { id, project_id },
qs
}
}
export default directCosts
Bug reports and pull requests are welcome on GitHub at https://github.com/procore/js-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
- Create PR with version change
npm version minor
- Merge PR
- Circle ci will release a new version of the package
The package is available as open source under the terms of the MIT License.
Manage Version is maintained by Procore Technologies.
Procore - building the software that builds the world.
Learn more about the #1 most widely used construction management software at procore.com