Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/(api)/_graphql/queries/getShipping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { gql } from '@apollo/client';

/*
From https://developer.ups.com/api/reference?loc=en_US#tag/Shipping_other
Shipping info returns:
- Address to ship to
- Box dimensions (length, width, height)
- Box weight

Takes returned items and puts them into params which will round up the shipping estimate
*/

export const getShippingEstimateQuery = gql`
query GetShippingEstimate(
$destination: String!
$weight: Float!
$length: Float!
$width: Float!
$height: Float!
) {
getShippingEstimate(
destination: $destination
weight: $weight
length: $length
width: $width
height: $height
) {
roundedUpTwo
}
}
`;
29 changes: 29 additions & 0 deletions app/(api)/ups_api/oauth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import fetch from 'node-fetch';

const client_id = 'PideuJgSmGvAyj5gffCmviGArkXRL8tS3T8Ec6bRLp4h1gwd';
const client_secret = 'NvROilwfopWTD8V6O0SYTZpzCce70jeoxV2jDmDM6iUEHcqxfnSI4LeIrxINGAAO';
const shipping_number = 'H6A563';
const shipping_speed = '12';

async function run() {
const formData = {
grant_type: 'authorization_code',
code: shipping_number,
redirect_uri: 'http://localhost:3000',
};

const resp = await fetch(`https://wwwcie.ups.com/security/v1/oauth/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization:
'Basic ' + Buffer.from(`${client_id}:${client_secret}`).toString('base64'),
},
body: new URLSearchParams(formData).toString(),
});

const data = await resp.text();
console.log(data);
}

run();
103 changes: 94 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"init:windows": "node --env-file=\".\\.env\" \".\\app\\(api)\\_utils\\mongodb\\dbInit.mjs\""
},
"dependencies": {
"@apollo/client": "^3.9.4",
"@apollo/client": "^3.9.6",
"@apollo/experimental-nextjs-app-support": "^0.8.0",
"graphql": "^16.8.1",
"mongodb": "^6.3.0",
"next": "14.0.4",
"node-fetch": "^3.3.2",
"react": "^18",
"react-dom": "^18",
"react-icons": "^4.11.0",
Expand Down