Chilkat Online Tools

Ruby / ShippingEasy API / Get Orders

Back to Collection Items

require 'chilkat'

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

http = Chilkat::CkHttp.new()

queryParams = Chilkat::CkJsonObject.new()
queryParams.UpdateString("api_signature","{{api_signature}}")
queryParams.UpdateString("api_timestamp","{{api_timestamp}}")
queryParams.UpdateString("api_key","{{API Key}}")

# resp is a CkHttpResponse
resp = http.QuickRequestParams("GET","https://app.shippingeasy.com/api/orders",queryParams)
if (http.get_LastMethodSuccess() == false)
    print http.lastErrorText() + "\n";
    exit
end

print resp.get_StatusCode().to_s() + "\n";
print resp.bodyStr() + "\n";

Curl Command

curl -G -d "api_signature=%7B%7Bapi_signature%7D%7D"
	-d "api_timestamp=%7B%7Bapi_timestamp%7D%7D"
	-d "api_key=%7B%7BAPI%20Key%7D%7D"
https://app.shippingeasy.com/api/orders

Postman Collection Item JSON

{
  "name": "Get Orders",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// calculate timestamp",
          "const timestamp = parseInt(Date.now() / 1000);",
          "console.log(\"timestamp: \" + timestamp);",
          "pm.variables.set(\"api_timestamp\", timestamp);",
          "",
          "// Set your API key and API secret as Postman environment variables, your key and secret are available at https://app.shippingeasy.com/settings/api_credentials",
          "const apiKey = pm.environment.get(\"API Key\");",
          "const apiSecret = pm.environment.get(\"API Secret\");",
          "",
          "// build signature string - https://shippingeasy.readme.io/docs/authentication-signing-requests#how-to-calculate-a-signature",
          "const signatureString = pm.request.method + \"&\" +",
          "  pm.request.url.getPath() + \"&\" +",
          "  \"api_key=\" + apiKey + \"&\" +",
          "  \"api_timestamp=\" + timestamp;",
          "console.log(\"signature string: \" + signatureString);",
          "",
          "// generate signature",
          "const apiSignature = CryptoJS.HmacSHA256(signatureString, apiSecret).toString(CryptoJS.enc.Hex);",
          "console.log(\"api request signature: \" + apiSignature);",
          "pm.variables.set(\"api_signature\", apiSignature);"
        ]
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "app.shippingeasy.com/api/orders?api_signature={{api_signature}}&api_timestamp={{api_timestamp}}&api_key={{API Key}}",
      "host": [
        "app",
        "shippingeasy",
        "com"
      ],
      "path": [
        "api",
        "orders"
      ],
      "query": [
        {
          "key": "api_signature",
          "value": "{{api_signature}}"
        },
        {
          "key": "api_timestamp",
          "value": "{{api_timestamp}}"
        },
        {
          "key": "api_key",
          "value": "{{API Key}}"
        }
      ]
    },
    "description": "Fetch orders"
  },
  "response": [
  ]
}