diff --git a/official/guides/create-carrier-curls/amazonmws.sh b/official/guides/create-carrier-curls/amazonmws.sh deleted file mode 100644 index d9e0d8d0..00000000 --- a/official/guides/create-carrier-curls/amazonmws.sh +++ /dev/null @@ -1,14 +0,0 @@ -curl -X POST https://api.easypost.com/v2/carrier_accounts \ - -u "$EASYPOST_API_KEY": \ - -H 'Content-Type: application/json' \ - -d '{ - "type": "AmazonMwsAccount", - "description": "AmazonMwsAccount", - "carrier_account": { - "credentials": { - "access_key_id": "VALUE", - "merchant_id": "VALUE", - "secret_key": "VALUE" - } - } -}' diff --git a/official/guides/create-carrier-curls/canadapost.sh b/official/guides/create-carrier-curls/canadapost.sh index 84da76ec..05613fe8 100644 --- a/official/guides/create-carrier-curls/canadapost.sh +++ b/official/guides/create-carrier-curls/canadapost.sh @@ -10,14 +10,18 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ "contract_id": "VALUE", "customer_number": "VALUE", "has_credit_card": "VALUE", - "not_platform": "VALUE" + "not_platform": "VALUE", + "zonos_api_key": "VALUE", + "zonos_enabled": "VALUE" }, "test_credentials": { "api_key": "VALUE", "contract_id": "VALUE", "customer_number": "VALUE", "has_credit_card": "VALUE", - "not_platform": "VALUE" + "not_platform": "VALUE", + "zonos_api_key": "VALUE", + "zonos_enabled": "VALUE" } } }' diff --git a/official/guides/create-carrier-curls/canadapost-default.sh b/official/guides/create-carrier-curls/canadapostwallet.sh similarity index 83% rename from official/guides/create-carrier-curls/canadapost-default.sh rename to official/guides/create-carrier-curls/canadapostwallet.sh index 96740480..fefa9262 100644 --- a/official/guides/create-carrier-curls/canadapost-default.sh +++ b/official/guides/create-carrier-curls/canadapostwallet.sh @@ -4,6 +4,6 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ -d '{ "carrier_account": { "type": "CanadaPostAccount", - "payment_mode": "aggregation" + "description": "CanadaPostAccount" } }' diff --git a/official/guides/create-carrier-curls/daipost.sh b/official/guides/create-carrier-curls/daipost.sh index 30af80c6..8a3c6b51 100644 --- a/official/guides/create-carrier-curls/daipost.sh +++ b/official/guides/create-carrier-curls/daipost.sh @@ -7,6 +7,7 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ "description": "DaiPostAccount", "credentials": { "account_code": "VALUE", + "api_key": "VALUE", "origin_terminal": "VALUE", "password": "VALUE", "username": "VALUE" diff --git a/official/guides/create-carrier-curls/deliverit.sh b/official/guides/create-carrier-curls/deliverit.sh deleted file mode 100644 index e8d4cd5d..00000000 --- a/official/guides/create-carrier-curls/deliverit.sh +++ /dev/null @@ -1,19 +0,0 @@ -curl -X POST https://api.easypost.com/v2/carrier_accounts \ - -u "$EASYPOST_API_KEY": \ - -H 'Content-Type: application/json' \ - -d '{ - "carrier_account": { - "type": "DeliverItAccount", - "description": "DeliverItAccount", - "credentials": { - "account_number": "VALUE", - "password": "VALUE", - "username": "VALUE" - }, - "test_credentials": { - "account_number": "VALUE", - "password": "VALUE", - "username": "VALUE" - } - } -}' diff --git a/official/guides/create-carrier-curls/deutschepostuk.sh b/official/guides/create-carrier-curls/deutschepostuk.sh index f2fc94d2..eed511f7 100644 --- a/official/guides/create-carrier-curls/deutschepostuk.sh +++ b/official/guides/create-carrier-curls/deutschepostuk.sh @@ -7,13 +7,19 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ "description": "DeutschePostUKAccount", "credentials": { "account_number": "VALUE", + "api_key": "VALUE", "client_id": "VALUE", - "client_secret": "VALUE" + "client_secret": "VALUE", + "customer_identification": "VALUE", + "customer_pricing_reference": "VALUE" }, "test_credentials": { "account_number": "VALUE", + "api_key": "VALUE", "client_id": "VALUE", - "client_secret": "VALUE" + "client_secret": "VALUE", + "customer_identification": "VALUE", + "customer_pricing_reference": "VALUE" } } }' diff --git a/official/guides/create-carrier-curls/dhlecs.sh b/official/guides/create-carrier-curls/dhlecs.sh index fe4e0a5d..3aac9c5f 100644 --- a/official/guides/create-carrier-curls/dhlecs.sh +++ b/official/guides/create-carrier-curls/dhlecs.sh @@ -8,12 +8,14 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ "credentials": { "client_id": "VALUE", "client_secret": "VALUE", - "distribution_center": "VALUE" + "distribution_center": "VALUE", + "pickup_id": "VALUE" }, "test_credentials": { "client_id": "VALUE", "client_secret": "VALUE", - "distribution_center": "VALUE" + "distribution_center": "VALUE", + "pickup_id": "VALUE" } } }' diff --git a/official/guides/create-carrier-curls/dhlecs-wallet.sh b/official/guides/create-carrier-curls/dhlecswallet.sh similarity index 73% rename from official/guides/create-carrier-curls/dhlecs-wallet.sh rename to official/guides/create-carrier-curls/dhlecswallet.sh index 3a281b61..a3259b68 100644 --- a/official/guides/create-carrier-curls/dhlecs-wallet.sh +++ b/official/guides/create-carrier-curls/dhlecswallet.sh @@ -4,7 +4,6 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ -d '{ "carrier_account": { "type": "DhlEcsAccount", - "description": "DhlEcsAccount", - "payment_mode": "aggregation" + "description": "DhlEcsAccount" } }' diff --git a/official/guides/create-carrier-curls/dhlexpress.sh b/official/guides/create-carrier-curls/dhlexpress.sh index 2132d8cd..2d21f40c 100644 --- a/official/guides/create-carrier-curls/dhlexpress.sh +++ b/official/guides/create-carrier-curls/dhlexpress.sh @@ -10,7 +10,9 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ "country": "VALUE", "is_reseller": "VALUE", "password": "VALUE", - "site_id": "VALUE" + "site_id": "VALUE", + "zonos_api_key": "VALUE", + "zonos_enabled": "VALUE" } } }' diff --git a/official/guides/create-carrier-curls/dhlexpresswallet.sh b/official/guides/create-carrier-curls/dhlexpresswallet.sh new file mode 100644 index 00000000..30e54500 --- /dev/null +++ b/official/guides/create-carrier-curls/dhlexpresswallet.sh @@ -0,0 +1,9 @@ +curl -X POST https://api.easypost.com/v2/carrier_accounts \ + -u "$EASYPOST_API_KEY": \ + -H 'Content-Type: application/json' \ + -d '{ + "carrier_account": { + "type": "DhlExpressAccount", + "description": "DhlExpressAccount" + } +}' diff --git a/official/guides/create-carrier-curls/fedexdefault.sh b/official/guides/create-carrier-curls/fedexdefault.sh new file mode 100644 index 00000000..21b6b301 --- /dev/null +++ b/official/guides/create-carrier-curls/fedexdefault.sh @@ -0,0 +1,16 @@ +curl -X POST https://api.easypost.com/v2/carrier_accounts/open \ + -u "$EASYPOST_API_KEY": \ + -H 'Content-Type: application/json' \ + -d '{ + "carrier_account": { + "type": "FedexDefaultAccount", + "name": "VALUE", + "street1": "VALUE", + "city": "VALUE", + "state": "VALUE", + "postal_code": "VALUE", + "country": "VALUE", + "phone": "VALUE", + "email": "VALUE" + } +}' diff --git a/official/guides/create-carrier-curls/firstmileconcise.sh b/official/guides/create-carrier-curls/firstmileconcise.sh deleted file mode 100644 index 72a693a1..00000000 --- a/official/guides/create-carrier-curls/firstmileconcise.sh +++ /dev/null @@ -1,19 +0,0 @@ -curl -X POST https://api.easypost.com/v2/carrier_accounts \ - -u "$EASYPOST_API_KEY": \ - -H 'Content-Type: application/json' \ - -d '{ - "carrier_account": { - "type": "FirstMileConciseAccount", - "description": "FirstMileConciseAccount", - "credentials": { - "account_number": "VALUE", - "password": "VALUE", - "username": "VALUE" - }, - "test_credentials": { - "account_number": "VALUE", - "password": "VALUE", - "username": "VALUE" - } - } -}' diff --git a/official/guides/create-carrier-curls/glsgroup.sh b/official/guides/create-carrier-curls/glsgroup.sh new file mode 100644 index 00000000..6088b2dc --- /dev/null +++ b/official/guides/create-carrier-curls/glsgroup.sh @@ -0,0 +1,19 @@ +curl -X POST https://api.easypost.com/v2/carrier_accounts \ + -u "$EASYPOST_API_KEY": \ + -H 'Content-Type: application/json' \ + -d '{ + "carrier_account": { + "type": "GlsGroupAccount", + "description": "GlsGroupAccount", + "credentials": { + "client_id": "VALUE", + "client_secret": "VALUE", + "contact_id": "VALUE" + }, + "test_credentials": { + "client_id": "VALUE", + "client_secret": "VALUE", + "contact_id": "VALUE" + } + } +}' diff --git a/official/guides/create-carrier-curls/gofo-wallet.sh b/official/guides/create-carrier-curls/gofowallet.sh similarity index 65% rename from official/guides/create-carrier-curls/gofo-wallet.sh rename to official/guides/create-carrier-curls/gofowallet.sh index 4644c3fa..e6712753 100644 --- a/official/guides/create-carrier-curls/gofo-wallet.sh +++ b/official/guides/create-carrier-curls/gofowallet.sh @@ -4,8 +4,9 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts/open \ -d '{ "carrier_account": { "type": "GofoWalletAccount", - "reference": "GOFO Wallet Account", - "description": "GOFO Wallet Account", - "origin_hub": "VALUE" + "description": "GofoWalletAccount", + "credentials": { + "origin_hub": "VALUE" + } } }' diff --git a/official/guides/create-carrier-curls/sendle.sh b/official/guides/create-carrier-curls/gori.sh similarity index 55% rename from official/guides/create-carrier-curls/sendle.sh rename to official/guides/create-carrier-curls/gori.sh index 7304ba87..83dfce23 100644 --- a/official/guides/create-carrier-curls/sendle.sh +++ b/official/guides/create-carrier-curls/gori.sh @@ -3,15 +3,15 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ -H 'Content-Type: application/json' \ -d '{ "carrier_account": { - "type": "SendleAccount", - "description": "SendleAccount", + "type": "GoriAccount", + "description": "GoriAccount", "credentials": { - "api_key": "VALUE", - "user_id": "VALUE" + "client_id": "VALUE", + "client_secret": "VALUE" }, "test_credentials": { - "api_key": "VALUE", - "user_id": "VALUE" + "client_id": "VALUE", + "client_secret": "VALUE" } } }' diff --git a/official/guides/create-carrier-curls/logissimo.sh b/official/guides/create-carrier-curls/logissimo.sh index f7fb8412..da38cc90 100644 --- a/official/guides/create-carrier-curls/logissimo.sh +++ b/official/guides/create-carrier-curls/logissimo.sh @@ -10,14 +10,18 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ "api_username": "VALUE", "client_id": "VALUE", "password": "VALUE", - "shipper_account_number": "VALUE" + "shipper_account_number": "VALUE", + "track_client_id": "VALUE", + "track_client_secret": "VALUE" }, "test_credentials": { "api_key": "VALUE", "api_username": "VALUE", "client_id": "VALUE", "password": "VALUE", - "shipper_account_number": "VALUE" + "shipper_account_number": "VALUE", + "track_client_id": "VALUE", + "track_client_secret": "VALUE" } } }' diff --git a/official/guides/create-carrier-curls/parcelforce.sh b/official/guides/create-carrier-curls/parcelforce.sh deleted file mode 100644 index c66c0de6..00000000 --- a/official/guides/create-carrier-curls/parcelforce.sh +++ /dev/null @@ -1,21 +0,0 @@ -curl -X POST https://api.easypost.com/v2/carrier_accounts \ - -u "$EASYPOST_API_KEY": \ - -H 'Content-Type: application/json' \ - -d '{ - "carrier_account": { - "type": "ParcelForceAccount", - "description": "ParcelForceAccount", - "credentials": { - "account_number": "VALUE", - "department_id": "VALUE", - "password": "VALUE", - "username": "VALUE" - }, - "test_credentials": { - "account_number": "VALUE", - "department_id": "VALUE", - "password": "VALUE", - "username": "VALUE" - } - } -}' diff --git a/official/guides/create-carrier-curls/royalmail.sh b/official/guides/create-carrier-curls/royalmail.sh index ef20542b..f253f737 100644 --- a/official/guides/create-carrier-curls/royalmail.sh +++ b/official/guides/create-carrier-curls/royalmail.sh @@ -2,9 +2,9 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ -u "$EASYPOST_API_KEY": \ -H 'Content-Type: application/json' \ -d '{ - "type": "RoyalMailAccount", - "description": "RoyalMailAccount", "carrier_account": { + "type": "RoyalMailAccount", + "description": "RoyalMailAccount", "credentials": { "account_number": "VALUE", "posting_location_number": "VALUE", diff --git a/official/guides/create-carrier-curls/pandion.sh b/official/guides/create-carrier-curls/tipsa.sh similarity index 56% rename from official/guides/create-carrier-curls/pandion.sh rename to official/guides/create-carrier-curls/tipsa.sh index 37edb15f..6275b761 100644 --- a/official/guides/create-carrier-curls/pandion.sh +++ b/official/guides/create-carrier-curls/tipsa.sh @@ -2,14 +2,13 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts \ -u "$EASYPOST_API_KEY": \ -H 'Content-Type: application/json' \ -d '{ - "type": "PandionAccount", - "description": "PandionAccount", "carrier_account": { + "type": "TipsaAccount", + "description": "TipsaAccount", "credentials": { - "api_key": "VALUE" - }, - "test_credentials": { - "api_key": "VALUE" + "agency_code": "VALUE", + "customer_code": "VALUE", + "password": "VALUE" } } }' diff --git a/official/guides/create-carrier-curls/toll.sh b/official/guides/create-carrier-curls/toll.sh deleted file mode 100644 index b4bdaee1..00000000 --- a/official/guides/create-carrier-curls/toll.sh +++ /dev/null @@ -1,19 +0,0 @@ -curl -X POST https://api.easypost.com/v2/carrier_accounts \ - -u "$EASYPOST_API_KEY": \ - -H 'Content-Type: application/json' \ - -d '{ - "type": "TollAccount", - "description": "TollAccount", - "carrier_account": { - "credentials": { - "account_number": "VALUE", - "business_unit": "VALUE", - "source_system_code": "VALUE" - }, - "test_credentials": { - "account_number": "VALUE", - "business_unit": "VALUE", - "source_system_code": "VALUE" - } - } -}' diff --git a/official/guides/create-carrier-curls/upsdap.sh b/official/guides/create-carrier-curls/upsdap.sh new file mode 100644 index 00000000..8720924b --- /dev/null +++ b/official/guides/create-carrier-curls/upsdap.sh @@ -0,0 +1,21 @@ +curl -X POST https://api.easypost.com/v2/carrier_accounts/open \ + -u "$EASYPOST_API_KEY": \ + -H 'Content-Type: application/json' \ + -d '{ + "carrier_account": { + "type": "UpsDapAccount", + "description": "VALUE", + "name": "VALUE", + "title": "VALUE", + "company": "VALUE", + "street1": "VALUE", + "street2": "VALUE", + "city": "VALUE", + "state": "VALUE", + "postal_code": "VALUE", + "country": "VALUE", + "website": "VALUE", + "email": "VALUE", + "phone": "VALUE" + } +}' diff --git a/official/guides/create-carrier-curls/upsiparcel.sh b/official/guides/create-carrier-curls/upsiparcel.sh deleted file mode 100644 index 18c6c429..00000000 --- a/official/guides/create-carrier-curls/upsiparcel.sh +++ /dev/null @@ -1,14 +0,0 @@ -curl -X POST https://api.easypost.com/v2/carrier_accounts \ - -u "$EASYPOST_API_KEY": \ - -H 'Content-Type: application/json' \ - -d '{ - "type": "UpsIparcelAccount", - "description": "UpsIparcelAccount", - "carrier_account": { - "credentials": { - "api_key": "VALUE", - "oauth_status": "VALUE", - "partner_oauth_url": "VALUE" - } - } -}' diff --git a/official/guides/create-carrier-curls/upsmailinnovations.sh b/official/guides/create-carrier-curls/upsmailinnovations.sh index d963e9cd..dd9c5523 100644 --- a/official/guides/create-carrier-curls/upsmailinnovations.sh +++ b/official/guides/create-carrier-curls/upsmailinnovations.sh @@ -1,4 +1,4 @@ -curl -X POST https://api.easypost.com/v2/carrier_accounts \ +curl -X POST https://api.easypost.com/v2/carrier_accounts/register_oauth \ -u "$EASYPOST_API_KEY": \ -H 'Content-Type: application/json' \ -d '{ diff --git a/official/guides/create-carrier-curls/upssurepost.sh b/official/guides/create-carrier-curls/upssurepost.sh index ae52cae8..5c4fae8d 100644 --- a/official/guides/create-carrier-curls/upssurepost.sh +++ b/official/guides/create-carrier-curls/upssurepost.sh @@ -1,4 +1,4 @@ -curl -X POST https://api.easypost.com/v2/carrier_accounts \ +curl -X POST https://api.easypost.com/v2/carrier_accounts/register_oauth \ -u "$EASYPOST_API_KEY": \ -H 'Content-Type: application/json' \ -d '{ diff --git a/official/guides/create-carrier-curls/uspsship.sh b/official/guides/create-carrier-curls/uspsship.sh new file mode 100644 index 00000000..8f1ed73e --- /dev/null +++ b/official/guides/create-carrier-curls/uspsship.sh @@ -0,0 +1,31 @@ +curl -X POST https://api.easypost.com/v2/carrier_accounts/register_oauth \ + -u "$EASYPOST_API_KEY": \ + -H 'Content-Type: application/json' \ + -d '{ + "carrier_account": { + "type": "UspsShipAccount", + "description": "UspsShipAccount", + "credentials": { + "account_number": "VALUE", + "address_city": "VALUE", + "address_state": "VALUE", + "address_street": "VALUE", + "address_zip": "VALUE", + "client_id": "VALUE", + "client_secret": "VALUE", + "company_name": "VALUE", + "contract_number": "VALUE", + "customer_registration_id": "VALUE", + "email": "VALUE", + "mailer_id": "VALUE", + "manifest_id": "VALUE", + "partner_oauth_url": "VALUE", + "phone": "VALUE", + "platform_account_number": "VALUE", + "refresh_token": "VALUE", + "returns_mailer_id": "VALUE", + "secondary_account_number": "VALUE", + "shipper_id": "VALUE" + } + } +}' diff --git a/official/guides/create-carrier-curls/uspsshipplatform.sh b/official/guides/create-carrier-curls/uspsshipplatform.sh new file mode 100644 index 00000000..94b67a85 --- /dev/null +++ b/official/guides/create-carrier-curls/uspsshipplatform.sh @@ -0,0 +1,19 @@ +curl -X POST https://api.easypost.com/v2/carrier_accounts \ + -u "$EASYPOST_API_KEY": \ + -H 'Content-Type: application/json' \ + -d '{ + "carrier_account": { + "type": "UspsShipPlatformAccount", + "description": "UspsShipPlatformAccount", + "credentials": { + "address_city": "VALUE", + "address_state": "VALUE", + "address_street": "VALUE", + "address_zip": "VALUE", + "company_name": "VALUE", + "email": "VALUE", + "phone": "VALUE", + "shipper_id": "VALUE" + } + } +}' diff --git a/official/guides/create-carrier-curls/uspswallet.sh b/official/guides/create-carrier-curls/uspswallet.sh new file mode 100644 index 00000000..bfe144da --- /dev/null +++ b/official/guides/create-carrier-curls/uspswallet.sh @@ -0,0 +1,9 @@ +curl -X POST https://api.easypost.com/v2/carrier_accounts \ + -u "$EASYPOST_API_KEY": \ + -H 'Content-Type: application/json' \ + -d '{ + "carrier_account": { + "type": "UspsAccount", + "description": "UspsAccount" + } +}' diff --git a/official/guides/create-carrier-curls/veho-wallet.sh b/official/guides/create-carrier-curls/vehowallet.sh similarity index 59% rename from official/guides/create-carrier-curls/veho-wallet.sh rename to official/guides/create-carrier-curls/vehowallet.sh index aeb5017e..5b78a22e 100644 --- a/official/guides/create-carrier-curls/veho-wallet.sh +++ b/official/guides/create-carrier-curls/vehowallet.sh @@ -4,9 +4,9 @@ curl -X POST https://api.easypost.com/v2/carrier_accounts/open \ -d '{ "carrier_account": { "type": "VehoWalletAccount", - "reference": "Veho Wallet Account", - "description": "Veho Wallet Account", - "company": "VALUE", - "agreed_to_terms_at": "VALUE" + "description": "VehoWalletAccount", + "credentials": { + "agreed_to_terms_at": "VALUE" + } } }' diff --git a/tools/build_create_carrier_curl_requests/README.md b/tools/build_create_carrier_curl_requests/README.md index edd8ca79..7320adae 100644 --- a/tools/build_create_carrier_curl_requests/README.md +++ b/tools/build_create_carrier_curl_requests/README.md @@ -1,8 +1,20 @@ # Build Create Carrier Curl Requests Tool -This tool creates a file containing all the create carrier account curl requests for all carriers on the EasyPost platform. +This tool generates all carrier create curl files from the `/carrier_types` endpoint. -EasyPost publishes these curl requests for convenience in this repo along with populating those requests on each carrier guide on our documentation. +EasyPost publishes these curl requests for convenience in this repo and uses them to populate each carrier guide in our docs. + +The output is intentionally fully automated. Whatever carrier types are available from `/carrier_types` at run time is the source of truth for what should be checked in. + +## Carrier Availability Feature Flags + +Some carriers are behind feature flags and will not be returned by `/carrier_types` unless the API user has the associated `available_for_presentation` flag enabled for that carrier. + +It is recommended to run this tool with the `Docs Tooling` EasyPost user, since that user is already configured with the needed carrier feature flags and should return the full list. + +If the Docs Tooling user is not available, the user running this tool must be enabled on the backend for all `available_for_presentation` feature flags. + +The tool also includes static fallbacks for carriers under `STATIC_CARRIER_TYPES`, which are currently known to be omitted from `/carrier_types` due to not being marked for presentation. ## Install @@ -16,6 +28,16 @@ venv/bin/pip install easypost ## Usage +The script automatically deletes and rebuilds `official/guides/create-carrier-curls` on every run. + ```shell EASYPOST_PROD_API_KEY=123... venv/bin/python build_curls.py ``` + +This workflow is required because it guarantees all of the following: + +- New carrier create curls are added automatically. +- Existing carrier create curls are refreshed with any updated values. +- Carrier create curls for carriers that are no longer available are removed automatically. + +Do not add one-off manual curl files to `official/guides/create-carrier-curls`. If a carrier is genuinely addable via API but does not appear in this tool output (for example, because it is currently marked unavailable on the EasyPost backend), we still do not check in manual exceptions. The next automated run will remove manual files anyway, and the intended process is fully automated. diff --git a/tools/build_create_carrier_curl_requests/build_curls.py b/tools/build_create_carrier_curl_requests/build_curls.py index be03d670..d77c0958 100644 --- a/tools/build_create_carrier_curl_requests/build_curls.py +++ b/tools/build_create_carrier_curl_requests/build_curls.py @@ -2,10 +2,12 @@ import json import os import re +import shutil +import carrier_builder_data +import carrier_builder_payloads import easypost - # Builds a file containing every create a Carrier Account cURL request via EasyPost # USAGE: EASYPOST_PROD_API_KEY=123... venv/bin/python build_curls.py @@ -13,39 +15,24 @@ LINE_BREAK_CHARS = " \\\n" END_CHARS = "\n" CUSTOM_WORKFLOW_CHARS = "## REQUIRES CUSTOM WORKFLOW ##\n" +OUTPUT_DESTINATION = os.path.join("..", "..", "official", "guides", "create-carrier-curls") + + +def reset_output_directory() -> None: + """Delete and recreate the output directory so every run is fully regenerated.""" + if os.path.exists(OUTPUT_DESTINATION): + shutil.rmtree(OUTPUT_DESTINATION) + + os.makedirs(OUTPUT_DESTINATION) -FEDEX_CUSTOM_WORKFLOW_CARRIERS = [ - "FedexAccount", - "FedexSmartpostAccount", -] -UPS_CUSTOM_WORKFLOW_CARRIERS = [ - "UpsDapAccount", -] -OAUTH_CUSTOM_WORKFLOW_CARRIERS = [ - "AmazonShippingAccount", - "UpsAccount" -] -MAERSK_CUSTOM_WORKFLOW_CARRIERS = [ - "MaerskAccount" -] -DOORDASH_CUSTOM_WORKFLOW_CARRIERS = [ - "DoorDashAccount" -] -WALLET_CARRIERS = [ - "CanadaPostAccount", - "DhlEcsAccount", -] def main(): + reset_output_directory() carrier_types = get_carrier_types() for carrier in sorted(carrier_types, key=lambda x: x["type"]): curl_request = build_carrier_curl_request(carrier) - output_destination = os.path.join("../", "../", "official", "guides", "create-carrier-curls") - if not os.path.exists(output_destination): - os.makedirs(output_destination) - with open( - os.path.join(output_destination, f'{carrier["type"].lower().replace("account", "")}.sh'), + os.path.join(OUTPUT_DESTINATION, f"{carrier['type'].lower().replace('account', '')}.sh"), "w", ) as carrier_curl_file: carrier_curl_file.write(re.sub(r"^.*?\n", "", curl_request)) @@ -56,12 +43,17 @@ def get_carrier_types(): client = easypost.EasyPostClient(API_KEY) carrier_accounts = client.carrier_account.types() + existing_types = {carrier["type"] for carrier in carrier_accounts} + for static_carrier_type in carrier_builder_data.STATIC_CARRIER_TYPES: + if static_carrier_type not in existing_types: + carrier_accounts.append({"type": static_carrier_type}) + return carrier_accounts def build_carrier_curl_request(carrier): """Builds a single cURL request for a carrier via EasyPost.""" - carrier_output = f'# {carrier.get("type")}\n' + carrier_output = f"# {carrier.get('type')}\n" carrier_output = add_curl_line(carrier_output, carrier) carrier_output = add_headers(carrier_output, carrier) carrier_output = add_credential_structure(carrier_output, carrier) @@ -71,16 +63,21 @@ def build_carrier_curl_request(carrier): def add_curl_line(carrier_output: str, carrier: dict[str, str]) -> str: """Add curl command and registration url.""" - if carrier["type"] in (FEDEX_CUSTOM_WORKFLOW_CARRIERS + UPS_CUSTOM_WORKFLOW_CARRIERS): - carrier_output += f"curl -X POST https://api.easypost.com/v2/carrier_accounts/register{LINE_BREAK_CHARS}" - elif carrier["type"] in OAUTH_CUSTOM_WORKFLOW_CARRIERS: - carrier_output += f"curl -X POST https://api.easypost.com/v2/carrier_accounts/register_oauth{LINE_BREAK_CHARS}" - else: - carrier_output += f"curl -X POST https://api.easypost.com/v2/carrier_accounts{LINE_BREAK_CHARS}" + endpoint = get_create_endpoint(carrier["type"]) + carrier_output += f"curl -X POST https://api.easypost.com/{endpoint}{LINE_BREAK_CHARS}" return carrier_output +def get_create_endpoint(carrier_type: str) -> str: + """Resolve create endpoint for a carrier account type.""" + for endpoint, carrier_types in carrier_builder_data.CARRIER_CREATE_ENDPOINT_OVERRIDES.items(): + if carrier_type in carrier_types: + return endpoint + + return carrier_builder_data.DEFAULT_CREATE_ENDPOINT + + def add_headers(carrier_output: str, carrier: dict[str, str]) -> str: """Add necessry headers and authentication.""" carrier_output += f' -u "$EASYPOST_API_KEY":{LINE_BREAK_CHARS}' @@ -90,13 +87,16 @@ def add_headers(carrier_output: str, carrier: dict[str, str]) -> str: def write_wallet_curl(carrier: dict[str, str], carrier_account_json: dict) -> None: - """Create a Wallet cURL for carriers that support EasyPost aggregation.""" + """Create a Wallet cURL for carriers that support EasyPost BYOCA and Wallet.""" wallet_json = copy.deepcopy(carrier_account_json) wallet_account = wallet_json["carrier_account"] wallet_account.pop("credentials", None) wallet_account.pop("test_credentials", None) - wallet_account["payment_mode"] = "aggregation" - wallet_output = f'# {carrier.get("type")} (EasyPost Wallet)\n' + # TODO: It is too difficult to properly assess the need for payment_mode as it + # is a case-by-base basis and we should not make assumptions for either the carrier + # or the user here; however, this could use some better documentation and distinction. + # wallet_account["payment_mode"] = "aggregation" + wallet_output = f"# {carrier.get('type')} (EasyPost Wallet)\n" wallet_output = add_curl_line(wallet_output, carrier) wallet_output = add_headers(wallet_output, carrier) wallet_output += f" -d '{json.dumps(wallet_json, indent=2)}'" @@ -105,18 +105,9 @@ def write_wallet_curl(carrier: dict[str, str], carrier_account_json: dict) -> No f"{LINE_BREAK_CHARS}{END_CHARS}", END_CHARS, ) - output_destination = os.path.join( - "..", - "..", - "official", - "guides", - "create-carrier-curls", - ) - if not os.path.exists(output_destination): - os.makedirs(output_destination) carrier_filename = carrier["type"].lower().replace("account", "") with open( - os.path.join(output_destination, f"{carrier_filename}-wallet.sh"), + os.path.join(OUTPUT_DESTINATION, f"{carrier_filename}wallet.sh"), "w", ) as wallet_file: wallet_file.write(re.sub(r"^.*?\n", "", wallet_output)) @@ -124,6 +115,18 @@ def write_wallet_curl(carrier: dict[str, str], carrier_account_json: dict) -> No def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> str: """Iterate over the carrier fields and print the credential structure.""" + if carrier["type"] == "UpsDapAccount": + carrier_account_json = carrier_builder_payloads.ups_dap_account_payload() + carrier_output += f" -d '{json.dumps(carrier_account_json, indent=2)}'" + carrier_output += END_CHARS + return carrier_output + + if carrier["type"] == "FedexDefaultAccount": + carrier_account_json = carrier_builder_payloads.fedex_default_account_payload() + carrier_output += f" -d '{json.dumps(carrier_account_json, indent=2)}'" + carrier_output += END_CHARS + return carrier_output + carrier_account_json = { "carrier_account": { "type": carrier["type"], @@ -133,7 +136,7 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st carrier_fields = carrier.get("fields").to_dict() # FedEx - if carrier["type"] in FEDEX_CUSTOM_WORKFLOW_CARRIERS: + if carrier["type"] in carrier_builder_data.FEDEX_CUSTOM_WORKFLOW_CARRIERS: carrier_account_json["carrier_account"]["registration_data"] = {} for category in carrier_fields["creation_fields"]: for item in carrier_fields["creation_fields"][category]: @@ -143,36 +146,8 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st carrier_output += END_CHARS carrier_output = carrier_output.replace(f"{LINE_BREAK_CHARS}{END_CHARS}", f"{END_CHARS}") # Maersk Parcel — custom static credential structure - elif carrier["type"] in MAERSK_CUSTOM_WORKFLOW_CARRIERS: - carrier_account_json = { - "carrier_account": { - "type": "MaerskAccount", - "description": "Maersk Account", - "reference": None, - "credentials": { - "first_name": "VALUE", - "last_name": "VALUE", - "company_name": "VALUE", - "email": "VALUE", - "phone": "VALUE", - "daily_number_of_shipments": "VALUE", - "channel": "VALUE", - "accepted_terms": "true", - "serial_number": "VALUE", - "origin_address_line_1": "VALUE", - "origin_address_line_2": "VALUE", - "origin_postal_code": "VALUE", - "origin_city": "VALUE", - "origin_state": "VALUE", - "billing_address_line_1": "VALUE", - "billing_address_line_2": "VALUE", - "billing_postal_code": "VALUE", - "billing_city": "VALUE", - "billing_state": "VALUE" - }, - "test_credentials": {} - } - } + elif carrier["type"] in carrier_builder_data.MAERSK_CUSTOM_WORKFLOW_CARRIERS: + carrier_account_json = carrier_builder_payloads.maersk_account_payload() carrier_output += f" -d '{json.dumps(carrier_account_json, indent=2)}'" carrier_output += END_CHARS @@ -180,48 +155,19 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st return carrier_output # UPS OAuth elif carrier["type"] == "UpsAccount": - carrier_account_json = { - "carrier_account_oauth_registrations": { - "type": "UpsAccount", - "account_number": "CUSTOMER UPS ACCOUNT NUMBER", - "description": "CUSTOMER ACCOUNT DESCRIPTION (optional)", - "reference": "UNIQUE ACCOUNT REFERENCE (optional)", - "return_to_url": "https://example.com (optional)" - } - } + carrier_account_json = carrier_builder_payloads.ups_oauth_registration_payload() carrier_output += f" -d '{json.dumps(carrier_account_json, indent=2)}'" carrier_output += END_CHARS return carrier_output # Amazon Shipping - elif carrier["type"] in OAUTH_CUSTOM_WORKFLOW_CARRIERS: - carrier_account_json = { - "carrier_account_oauth_registrations": { - "type": "AmazonShippingAccount", - "description": "My Shipping Account (optional)", - "reference": "Internal reference id (optional)", - "return_to_url": "https://example.com (optional)", - "credentials": { - "account_type": "shipper", - "account_country": "US" - } - } - } + elif carrier["type"] in carrier_builder_data.OAUTH_CUSTOM_WORKFLOW_CARRIERS: + carrier_account_json = carrier_builder_payloads.amazon_shipping_oauth_registration_payload() carrier_output += f" -d '{json.dumps(carrier_account_json, indent=2)}'" carrier_output += END_CHARS # DoorDash - elif carrier["type"] in DOORDASH_CUSTOM_WORKFLOW_CARRIERS: - carrier_account_json = { - "billToEasyPost": False, - "credentials": { - "developer_id": "VALUE", - "key_id": "VALUE", - "signing_secret": "VALUE", - "pickup_external_business_id": "VALUE" - }, - "test_credentials": {}, - "type": "DoorDashAccount" - } + elif carrier["type"] in carrier_builder_data.DOORDASH_CUSTOM_WORKFLOW_CARRIERS: + carrier_account_json = carrier_builder_payloads.doordash_account_payload() carrier_output = ( "# DoorDashAccount\n" @@ -229,10 +175,7 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st "-H 'Content-Type: application/json' " "-H 'X-EasyPost-User-Id: ' " "https://api.easypost.com/v2/carrier_accounts " - "-d '" - + json.dumps(carrier_account_json, indent=2) - + "'" - + END_CHARS + "-d '" + json.dumps(carrier_account_json, indent=2) + "'" + END_CHARS ) return carrier_output # Normal carriers @@ -242,32 +185,32 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st # top_level here means `credentials`, `test_credentials`, # or `custom_workflow` for top_level in carrier_fields: - # TODO: If there is a custom_workflow such as 3rd party auth + # If there is a custom_workflow such as 3rd party auth # or a similar flow, warn about that here. The credential - # structure will differ from a normal carrier account and is - # currently not automated. + # structure will differ from a normal carrier account and is not automated. if top_level == "custom_workflow": end += CUSTOM_WORKFLOW_CHARS else: top_level_carrier_fields = carrier_fields[top_level] for item in top_level_carrier_fields: - if (carrier_account_json["carrier_account"].get(top_level)is None): + if carrier_account_json["carrier_account"].get(top_level) is None: carrier_account_json["carrier_account"][top_level] = {} carrier_account_json["carrier_account"][top_level][item] = "VALUE" - carrier_output += (f" -d '{json.dumps(carrier_account_json, indent=2)}'") + carrier_output += f" -d '{json.dumps(carrier_account_json, indent=2)}'" carrier_output += end carrier_output = carrier_output.replace( f"{LINE_BREAK_CHARS}{END_CHARS}", END_CHARS, ) - if carrier["type"] in WALLET_CARRIERS: + if carrier["type"] in carrier_builder_data.BYOCA_AND_WALLET_CARRIER_TYPES: write_wallet_curl(carrier, carrier_account_json) return carrier_output + if __name__ == "__main__": main() diff --git a/tools/build_create_carrier_curl_requests/carrier_builder_data.py b/tools/build_create_carrier_curl_requests/carrier_builder_data.py new file mode 100644 index 00000000..3573402d --- /dev/null +++ b/tools/build_create_carrier_curl_requests/carrier_builder_data.py @@ -0,0 +1,61 @@ +DEFAULT_CREATE_ENDPOINT = "v2/carrier_accounts" + +# Keep this focused on endpoint selection; payload one-offs are handled separately. +CARRIER_CREATE_ENDPOINT_OVERRIDES = { + "v2/carrier_accounts/open": { + "FedexDefaultAccount", + "GofoWalletAccount", + "UpsDapAccount", + "UniUniWalletAccount", + "VehoWalletAccount", + }, + "v2/carrier_accounts/register": { + "FedexAccount", + "FedexSmartpostAccount", + }, + "v2/carrier_accounts/register_oauth": { + "AmazonShippingAccount", + "UpsAccount", + "UpsMailInnovationsAccount", + "UpsSurepostAccount", + "UspsShipAccount", + }, +} + +# Carrier account types that should always be emitted even when omitted by +# /carrier_types (eg: due to being marked unavailable for presentation). +STATIC_CARRIER_TYPES = [ + "FedexDefaultAccount", + "UpsDapAccount", +] + +FEDEX_CUSTOM_WORKFLOW_CARRIERS = [ + "FedexAccount", + "FedexSmartpostAccount", +] + +UPS_CUSTOM_WORKFLOW_CARRIERS = [ + "UpsDapAccount", +] + +OAUTH_CUSTOM_WORKFLOW_CARRIERS = [ + "AmazonShippingAccount", + "UpsAccount", +] + +MAERSK_CUSTOM_WORKFLOW_CARRIERS = [ + "MaerskAccount", +] + +DOORDASH_CUSTOM_WORKFLOW_CARRIERS = [ + "DoorDashAccount", +] + +# The following are both a BYOCA (Bring Your Own Carrier Account) and +# wallet carrier type depending on what `payment_type` is set to. +BYOCA_AND_WALLET_CARRIER_TYPES = [ + "CanadaPostAccount", + "DhlEcsAccount", + "DhlExpressAccount", + "UspsAccount", +] diff --git a/tools/build_create_carrier_curl_requests/carrier_builder_payloads.py b/tools/build_create_carrier_curl_requests/carrier_builder_payloads.py new file mode 100644 index 00000000..18bb5208 --- /dev/null +++ b/tools/build_create_carrier_curl_requests/carrier_builder_payloads.py @@ -0,0 +1,108 @@ +def maersk_account_payload() -> dict: + return { + "carrier_account": { + "type": "MaerskAccount", + "description": "Maersk Account", + "reference": None, + "credentials": { + "first_name": "VALUE", + "last_name": "VALUE", + "company_name": "VALUE", + "email": "VALUE", + "phone": "VALUE", + "daily_number_of_shipments": "VALUE", + "channel": "VALUE", + "accepted_terms": "true", + "serial_number": "VALUE", + "origin_address_line_1": "VALUE", + "origin_address_line_2": "VALUE", + "origin_postal_code": "VALUE", + "origin_city": "VALUE", + "origin_state": "VALUE", + "billing_address_line_1": "VALUE", + "billing_address_line_2": "VALUE", + "billing_postal_code": "VALUE", + "billing_city": "VALUE", + "billing_state": "VALUE", + }, + "test_credentials": {}, + } + } + + +def ups_oauth_registration_payload() -> dict: + return { + "carrier_account_oauth_registrations": { + "type": "UpsAccount", + "account_number": "CUSTOMER UPS ACCOUNT NUMBER", + "description": "CUSTOMER ACCOUNT DESCRIPTION (optional)", + "reference": "UNIQUE ACCOUNT REFERENCE (optional)", + "return_to_url": "https://example.com (optional)", + } + } + + +def amazon_shipping_oauth_registration_payload() -> dict: + return { + "carrier_account_oauth_registrations": { + "type": "AmazonShippingAccount", + "description": "My Shipping Account (optional)", + "reference": "Internal reference id (optional)", + "return_to_url": "https://example.com (optional)", + "credentials": { + "account_type": "shipper", + "account_country": "US", + }, + } + } + + +def doordash_account_payload() -> dict: + return { + "billToEasyPost": False, + "credentials": { + "developer_id": "VALUE", + "key_id": "VALUE", + "signing_secret": "VALUE", + "pickup_external_business_id": "VALUE", + }, + "test_credentials": {}, + "type": "DoorDashAccount", + } + + +def ups_dap_account_payload() -> dict: + return { + "carrier_account": { + "type": "UpsDapAccount", + "description": "VALUE", + "name": "VALUE", + "title": "VALUE", + "company": "VALUE", + "street1": "VALUE", + "street2": "VALUE", + "city": "VALUE", + "state": "VALUE", + "postal_code": "VALUE", + "country": "VALUE", + "website": "VALUE", + "email": "VALUE", + "phone": "VALUE", + } + } + + +def fedex_default_account_payload() -> dict: + return { + "carrier_account": { + "type": "FedexDefaultAccount", + "name": "VALUE", + "street1": "VALUE", + "city": "VALUE", + "state": "VALUE", + "postal_code": "VALUE", + "country": "VALUE", + "phone": "VALUE", + "email": "VALUE", + } + }