Chilkat Online Tools

Node.js / Afterpay Online US API v2 / Update Shipping Courier

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

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

    var http = new chilkat.Http();
    var success;

    http.BasicAuth = true;
    http.Login = "100100248";
    http.Password = "117f3fe5a01a0e400f3e4782baf8ffa43a9d21e9217a15f50d545bc72480d081ecaecc1d6a42ac7a785b7437232bd4cf62dbee679b78a75a3892547059018f9b";

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "shippedAt": "2015-01-01T00:00:00Z",
    //   "name": "CourierPost",
    //   "tracking": "AA999999999AA",
    //   "priority": "STANDARD"
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("shippedAt","2015-01-01T00:00:00Z");
    json.UpdateString("name","CourierPost");
    json.UpdateString("tracking","AA999999999AA");
    json.UpdateString("priority","STANDARD");

    http.SetRequestHeader("Content-Type","application/json");
    http.SetRequestHeader("Accept","application/json");

    var sbRequestBody = new chilkat.StringBuilder();
    json.EmitSb(sbRequestBody);

    // resp: HttpResponse
    var resp = http.PTextSb("PUT","https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/courier",sbRequestBody,"utf-8","application/json",false,false);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X PUT
	-u '100100248:117f3fe5a01a0e400f3e4782baf8ffa43a9d21e9217a15f50d545bc72480d081ecaecc1d6a42ac7a785b7437232bd4cf62dbee679b78a75a3892547059018f9b'
	-H "Accept: application/json"
	-H "Content-Type: application/json"
	-d '{
	"shippedAt": "2015-01-01T00:00:00Z",
	"name": "CourierPost",
	"tracking": "AA999999999AA",
	"priority": "STANDARD"
}'
https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/courier

Postman Collection Item JSON

{
  "name": "Update Shipping Courier",
  "event": [
    {
      "listen": "test",
      "script": {
        "id": "298e1176-40a1-40ea-adae-d417963f228f",
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"shippedAt\": \"2015-01-01T00:00:00Z\",\n\t\"name\": \"CourierPost\",\n\t\"tracking\": \"AA999999999AA\",\n\t\"priority\": \"STANDARD\"\n}"
    },
    "url": {
      "raw": "https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/courier",
      "protocol": "https",
      "host": [
        "api",
        "us-sandbox",
        "afterpay",
        "com"
      ],
      "path": [
        "v2",
        "payments",
        "{{id}}",
        "courier"
      ]
    },
    "description": "This resource updates a payment with new shipping courier information. The Afterpay customer support team utilise the shipping courier information when enquiring on the outcome of an order."
  },
  "response": [
  ]
}