Chilkat Online Tools

Android / Coupa Postman Collection - OAuth - Master / Add contract term

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean success;

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

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

    // <?xml version="1.0" encoding="UTF-8"?>
    // <contract-term>
    //     <name>API Contract Term 1</name>
    //     <contract-term-type>PriceRangeContractTerm</contract-term-type>
    //     <use-pct-discounts type="boolean">true</use-pct-discounts>
    //     <tier-1-upper-bound type="decimal">15.0</tier-1-upper-bound>
    //     <tier-1-disc-pct type="decimal">6.0</tier-1-disc-pct>
    //     <tier-2-disc-pct type="decimal">7.0</tier-2-disc-pct>
    // </contract-term>
    // 

    CkXml xml = new CkXml();
    xml.put_Tag("contract-term");
    xml.UpdateChildContent("name","API Contract Term 1");
    xml.UpdateChildContent("contract-term-type","PriceRangeContractTerm");
    xml.UpdateAttrAt("use-pct-discounts",true,"type","boolean");
    xml.UpdateChildContent("use-pct-discounts","true");
    xml.UpdateAttrAt("tier-1-upper-bound",true,"type","decimal");
    xml.UpdateChildContent("tier-1-upper-bound","15.0");
    xml.UpdateAttrAt("tier-1-disc-pct",true,"type","decimal");
    xml.UpdateChildContent("tier-1-disc-pct","6.0");
    xml.UpdateAttrAt("tier-2-disc-pct",true,"type","decimal");
    xml.UpdateChildContent("tier-2-disc-pct","7.0");

    // Adds the "Authorization: Bearer <access_token>" header.
    http.put_AuthToken("<access_token>");

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    xml.GetXmlSb(sbRequestBody);

    CkHttpResponse resp = http.PTextSb("POST","https://domain.com/contracts/:id/contract_terms",sbRequestBody,"utf-8","application/xml",false,false);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    Log.i(TAG, String.valueOf(resp.get_StatusCode()));
    Log.i(TAG, resp.bodyStr());


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '<?xml version="1.0" encoding="UTF-8"?>
<contract-term>
    <name>API Contract Term 1</name>
    <contract-term-type>PriceRangeContractTerm</contract-term-type>
    <use-pct-discounts type="boolean">true</use-pct-discounts>
    <tier-1-upper-bound type="decimal">15.0</tier-1-upper-bound>
    <tier-1-disc-pct type="decimal">6.0</tier-1-disc-pct>
    <tier-2-disc-pct type="decimal">7.0</tier-2-disc-pct>
</contract-term>'
https://domain.com/contracts/:id/contract_terms

Postman Collection Item JSON

{
  "name": "Add contract term",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<contract-term>\n    <name>API Contract Term 1</name>\n    <contract-term-type>PriceRangeContractTerm</contract-term-type>\n    <use-pct-discounts type=\"boolean\">true</use-pct-discounts>\n    <tier-1-upper-bound type=\"decimal\">15.0</tier-1-upper-bound>\n    <tier-1-disc-pct type=\"decimal\">6.0</tier-1-disc-pct>\n    <tier-2-disc-pct type=\"decimal\">7.0</tier-2-disc-pct>\n</contract-term>",
      "options": {
        "raw": {
          "language": "xml"
        }
      }
    },
    "url": {
      "raw": "{{URL}}/contracts/:id/contract_terms",
      "host": [
        "{{URL}}"
      ],
      "path": [
        "contracts",
        ":id",
        "contract_terms"
      ],
      "variable": [
        {
          "key": "id",
          "value": "377",
          "type": "string"
        }
      ]
    }
  },
  "response": [
  ]
}