### Go example for listing coupon subscriptions Source: https://docs.withorb.com/api-reference/coupon/list-coupon-subscriptions Go example using net/http to GET the coupon subscriptions endpoint. Prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/coupons/{coupon_id}/subscriptions" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Python requests example for listing coupon subscriptions Source: https://docs.withorb.com/api-reference/coupon/list-coupon-subscriptions Python example using the requests library to GET the coupon subscriptions endpoint. Requires the requests library to be installed. ```python import requests url = "https://api.withorb.com/v1/coupons/{coupon_id}/subscriptions" headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers) print(response.text) ``` -------------------------------- ### Ruby Net::HTTP example for listing coupon subscriptions Source: https://docs.withorb.com/api-reference/coupon/list-coupon-subscriptions Ruby example using Net::HTTP to GET the coupon subscriptions endpoint. Prints the response body. ```ruby require 'uri' require 'net/http' url = URI("https://api.withorb.com/v1/coupons/{coupon_id}/subscriptions") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` -------------------------------- ### Go GET request for license usage Source: https://docs.withorb.com/api-reference/license/get-usage-for-a-license-by-external-license-id Go example using net/http to fetch license usage. Prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/licenses/external_licenses/{external_license_id}/usage" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Go example to fetch subscription costs Source: https://docs.withorb.com/api-reference/subscription/fetch-subscription-costs Go example using net/http to fetch subscription costs. Replace {subscription_id} and as needed. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/subscriptions/{subscription_id}/costs" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### PHP cURL: Create plan version by external ID Source: https://docs.withorb.com/api-reference/plan/create-plan-version-by-external-id Uses cURL to POST to the endpoint with a JSON-encoded body. The example is truncated in the source, showing the beginning of the request setup and the start of the payload. ```php "https://api.withorb.com/v1/plans/external_plan_id/{external_plan_id}/versions", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode([ 'version' => 123, 'add_prices' => [ [ 'price' => [ 'model_type' => 'unit', 'unit_config' => [ 'unit_amount' => '', 'scaling_factor' => 123, 'prorated' => false ], ``` -------------------------------- ### Fetch plan with Go Source: https://docs.withorb.com/api-reference/plan/fetch-plan Go example using net/http to fetch a plan. Replace {plan_id} and with your values. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/plans/{plan_id}" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Install Go SDK Source: https://docs.withorb.com/essentials/sdk Install the Orb Go SDK using go get. ```bash go get github.com/orbcorp/orb-go ``` -------------------------------- ### Go example for evaluate preview events Source: https://docs.withorb.com/api-reference/price/evaluate-preview-events Uses net/http to POST the payload as a string reader. Prints the response body. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/prices/evaluate_preview_events" payload := strings.NewReader("{\n \"timeframe_start\": \"2023-11-07T05:31:56Z\",\n \"timeframe_end\": \"2023-11-07T05:31:56Z\",\n \"customer_id\": \"\",\n \"external_customer_id\": \"\",\n \"events\": [],\n \"price_evaluations\": []\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Go example for evaluating multiple prices Source: https://docs.withorb.com/api-reference/price/evaluate-multiple-prices Uses net/http to POST a JSON string payload and prints the response body. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/prices/evaluate" payload := strings.NewReader("{\n \"timeframe_start\": \"2023-11-07T05:31:56Z\",\n \"timeframe_end\": \"2023-11-07T05:31:56Z\",\n \"customer_id\": \"\",\n \"external_customer_id\": \"\",\n \"price_evaluations\": []\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Java Unirest example for listing coupon subscriptions Source: https://docs.withorb.com/api-reference/coupon/list-coupon-subscriptions Java example using Unirest to GET the coupon subscriptions endpoint. Returns an HttpResponse. ```java HttpResponse response = Unirest.get("https://api.withorb.com/v1/coupons/{coupon_id}/subscriptions") .header("Authorization", "Bearer ") .asString(); ``` -------------------------------- ### PHP cURL example for listing coupon subscriptions Source: https://docs.withorb.com/api-reference/coupon/list-coupon-subscriptions PHP example using cURL to GET the coupon subscriptions endpoint. Handles errors and prints the response. ```php "https://api.withorb.com/v1/coupons/{coupon_id}/subscriptions", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "Authorization: Bearer " ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ``` -------------------------------- ### Go: Fetch Plan Version Source: https://docs.withorb.com/api-reference/plan/fetch-plan-version Go example using net/http to fetch a plan version. It creates a GET request with the Authorization header and prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/plans/{plan_id}/versions/{version}" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Go example for fetching subscription schedule Source: https://docs.withorb.com/api-reference/subscription/fetch-subscription-schedule Uses net/http to send a GET request to the subscription schedule endpoint and prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/subscriptions/{subscription_id}/schedule" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### JavaScript fetch example for listing coupon subscriptions Source: https://docs.withorb.com/api-reference/coupon/list-coupon-subscriptions JavaScript example using fetch to GET the coupon subscriptions endpoint. Logs the response JSON to the console. ```javascript const options = {method: 'GET', headers: {Authorization: 'Bearer '}}; fetch('https://api.withorb.com/v1/coupons/{coupon_id}/subscriptions', options) .then(res => res.json()) .then(res => console.log(res)) .catch(err => console.error(err)); ``` -------------------------------- ### Go GET subscription change Source: https://docs.withorb.com/api-reference/subscription-change/fetch-subscription-change Go example using net/http to fetch a subscription change. Creates a GET request with the Authorization header and prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/subscription_changes/{subscription_change_id}" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Go: Fetch backfill with net/http Source: https://docs.withorb.com/api-reference/event/fetch-backfill Go example using the standard net/http package to fetch a backfill. Replace {backfill_id} and with your values. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/events/backfills/{backfill_id}" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Go example to fetch customer credit balance Source: https://docs.withorb.com/api-reference/credit/fetch-customer-credit-balance Uses the net/http package to send a GET request to the Orb API. Prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/customers/{customer_id}/credits" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Java Unirest GET subscription change Source: https://docs.withorb.com/api-reference/subscription-change/fetch-subscription-change Java example using the Unirest HTTP library to fetch a subscription change. Sends a GET request with the Authorization header and returns the response as a string. ```java HttpResponse response = Unirest.get("https://api.withorb.com/v1/subscription_changes/{subscription_change_id}") .header("Authorization", "Bearer ") .asString(); ``` -------------------------------- ### Ruby GET subscription change Source: https://docs.withorb.com/api-reference/subscription-change/fetch-subscription-change Ruby example using Net::HTTP to fetch a subscription change. Sets up an HTTPS connection, sends a GET request with the Authorization header, and prints the response body. ```ruby require 'uri' require 'net/http' url = URI("https://api.withorb.com/v1/subscription_changes/{subscription_change_id}") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` -------------------------------- ### Fetch invoice with Ruby Source: https://docs.withorb.com/api-reference/invoice/fetch-invoice Ruby example using net/http to GET an invoice. Replace {invoice_id} and before running. ```ruby require 'uri' require 'net/http' url = URI("https://api.withorb.com/v1/invoices/{invoice_id}") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` -------------------------------- ### Go Example for Create Subscription Source: https://docs.withorb.com/api-reference/subscription/create-subscription Shows how to create a subscription using Go. The code constructs an HTTP POST request to the Orb API with a JSON payload containing subscription details. Requires the net/http, strings, and io packages. ```Go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/subscriptions" payload := strings.NewReader("{\n \"usage_customer_ids\": [\n \"\"\n ],\n \"filter\": \"my_property > 100 AND my_other_property = 'bar'\",\n \"metadata\": {},\n \"plan_id\": \"ZMwNQefe7J3ecf7W\",\n \"external_plan_id\": \"ZMwNQefe7J3ecf7W\",\n \"price_overrides\": [\n \"\"\n ],\n \"per_credit_overage_amount\": 123,\n \"credits_overage_rate\": 123,\n \"trial_duration_days\": 500000,\n \"net_terms\": 123,\n \"auto_collection\": true,\n \"auto_issuance\": true,\n \"default_invoice_memo\": \"\",\n \"coupon_redemption_code\": \"\",\n \"invoicing_threshold\": \"10.00\",\n \"initial_phase_order\": 2,\n \"add_prices\": [\n {\n \"price_id\": \"h74gfhdjvn7ujokd\",\n \"external_price_id\": \"external_price_id\",\n \"price\": {\n \"model_type\": \"unit\",\n \"unit_config\": {\n \"unit_amount\": \"\",\n \"scaling_factor\": 123,\n \"prorated\": false\n },\n \"name\": \"Annual fee\",\n \"item_id\": \"\",\n \"metadata\": {},\n \"external_price_id\": \"\",\n \"dimensional_price_configuration\": {\n \"dimension_values\": [\n \"\"\n ],\n \"dimensional_price_group_id\": \"\",\n \"external_dimensional_price_group_id\": ``` -------------------------------- ### Fetch invoice with Go Source: https://docs.withorb.com/api-reference/invoice/fetch-invoice Go example using net/http to GET an invoice. Replace {invoice_id} and before running. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/invoices/{invoice_id}" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Go example to list invoices Source: https://docs.withorb.com/api-reference/invoice/list-invoices Go example using net/http to call the List invoices endpoint. Prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/invoices" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) } ``` -------------------------------- ### Go example for creating a plan version Source: https://docs.withorb.com/api-reference/plan/create-plan-version Sends a POST request to the Orb API using Go's net/http package. Builds a JSON payload with version and price modifications, sends it, and prints the response body. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.withorb.com/v1/plans/{plan_id}/versions" payload := strings.NewReader("{\n \"version\": 123,\n \"add_prices\": [\n {\n \"price\": {\n \"model_type\": \"unit\",\n \"unit_config\": {\n \"unit_amount\": \"\",\n \"scaling_factor\": 123,\n \"prorated\": false\n },\n \"name\": \"Annual fee\",\n \"item_id\": \"\",\n \"metadata\": {},\n \"external_price_id\": \"\",\n \"dimensional_price_configuration\": {\n \"dimension_values\": [\n \"\"\n ],\n \"dimensional_price_group_id\": \"\",\n \"external_dimensional_price_group_id\": \"\"\n },\n \"license_type_id\": \"\",\n \"billable_metric_id\": \"\",\n \"billed_in_advance\": true,\n \"fixed_price_quantity\": 123,\n \"invoice_grouping_key\": \"\",\n \"billing_cycle_configuration\": {\n \"duration\": 123\n },\n \"invoicing_cycle_configuration\": {\n \"duration\": 123\n },\n \"conversion_rate\": 123,\n \"conversion_rate_config\": {\n \"conversion_rate_type\": \"unit\",\n \"unit_config\": {\n \"unit_amount\": \"\"\n }\n },\n \"currency\": \"\",\n \"reference_id\": \"\"\n },\n \"allocation_price\": {\n \"currency\": \"USD\",\n \"amount\": \"10.00\",\n \"cadence\": \"monthly\",\n \"metadata\": {},\n \"expires_at_end_of_cadence\": true,\n \"custom_expiration\": {\n \"duration\": 123\n },\n \"filters\": [\n {\n \"field\": \"item_id\",\n \"values\": [\n \"\"\n ]\n }\n ],\n \"per_unit_cost_basis\": \"0.00\",\n \"item_id\": \"\",\n \"license_type_id\": \"\"\n },\n \"license_allocation_price\": {\n \"model_type\": \"unit\",\n \"unit_config\": {\n \"unit_amount\": \"\",\n \"scaling_factor\": 123,\n \"prorated\": false\n },\n \"name\": \"Annual fee\",\n \"item_id\": \"\",\n \"license_allocations\": [\n {\n \"currency\": \"\",\n \"amount\": \"\",\n \"write_off_overage\": true\n }\n ],\n \"metadata\": {},\n \"external_price_id\": \"\",\n \"dimensional_price_configuration\": {\n \"dimension_values\": [\n \"\"\n ],\n \"dimensional_price_group_id\": \"\",\n \"external_dimensional_price_group_id\": \"\"\n },\n \"license_type_id\": \"\",\n \"billable_metric_id\": \"\",\n \"billed_in_advance\": true,\n \"fixed_price_quantity\": 123,\n \"invoice_grouping_key\": \"\",\n \"billing_cycle_configuration\": {\n \"duration\": 123\n },\n \"invoicing_cycle_configuration\": {\n \"duration\": 123\n },\n \"conversion_rate\": 123,\n \"conversion_rate_config\": {\n \"conversion_rate_type\": \"unit\",\n \"unit_config\": {\n \"unit_amount\": \"\"\n }\n },\n \"currency\": \"\",\n \"reference_id\": \"\"\n },\n \"plan_phase_order\": 123\n }\n ],\n \"remove_prices\": [\n {\n \"price_id\": \"\",\n \"plan_phase_order\": 123\n }\n ],\n \"replace_prices\": [\n {\n \"replaces_price_id\": \"\",\n \"price\": {\n \"model_type\": \"unit\",\n \"unit_config\": {\n \"unit_amount\": \"\",\n \"scaling_factor\": 123,\n \"prorated\": false\n },\n \"name\": \"Annual fee\",\n \"item_id\": \"\",\n \"metadata\": {},\n \"external_price_id\": \"\",\n \"dimensional_price_configuration\": {\n \"dimension_values\": [\n \"\"\n ],\n \"dimensional_price_group_id\": \"\",\n \"external_dimensional_price_group_id\": \"\"\n },\n \"license_type_id\": \"\",\n \"billable_metric_id\": \"\",\n \"billed_in_advance\": true,\n \"fixed_price_quantity\": 123,\n \"invoice_grouping_key\": \"\",\n \"billing_cycle_configuration\": {\n \"duration\": 123\n },\n \"invoicing_cycle_configuration\": {\n \"duration\": 123\n },\n \"conversion_rate\": 123,\n \"conversion_rate_config\": {\n \"conversion_rate_type\": \"unit\",\n \"unit_config\": {\n \"unit_amount\": \"\"\n }\n },\n \"currency\": \"\",\n \"reference_id\": \"\"\n }\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### PHP cURL example for creating plan version by external ID Source: https://docs.withorb.com/api-reference/plan/create-plan-version-by-external-id Uses PHP cURL to POST to the same endpoint. The request body is not shown in this snippet, but the setup includes the URL, method, and headers. The example is incomplete as the body is missing. ```php "https://api.withorb.com/v1/plans/external_plan_id/{external_plan_id}/versions", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", ```