Chilkat Online Tools

Swift3 / Zoho CRM REST APIs / Sales Orders

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

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

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

    // {
    //   "data": [
    //     {
    //       "Owner": {
    //         "id": "{{user-id}}"
    //       },
    //       "Deal_Name": {
    //         "id": "{{deal-id}}"
    //       },
    //       "Account_Name": {
    //         "id": "{{account-id}}"
    //       },
    //       "Quote_Name": {
    //         "id": "{{quote-id}}"
    //       },
    //       "Contact_Name": {
    //         "id": "{{contact-id}}"
    //       },
    //       "Discount": 127.67,
    //       "Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
    //       "Customer_No": "Customer_No",
    //       "Shipping_State": "Shipping_State",
    //       "Tax": 127.67,
    //       "Billing_Country": "Billing_Country",
    //       "Carrier": "USPS",
    //       "Status": "Delivered",
    //       "Sales_Commission": 127.67,
    //       "Due_Date": "2018-01-25",
    //       "Billing_Street": "Billing_Street",
    //       "Adjustment": 127.67,
    //       "Terms_and_Conditions": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
    //       "Billing_Code": "Billing_Code",
    //       "Product_Details": [
    //         {
    //           "product": {
    //             "id": "1000000071967"
    //           },
    //           "quantity": 150,
    //           "Discount": 20,
    //           "product_description": "product_description",
    //           "Unit Price": 10,
    //           "line_tax": [
    //             {
    //               "percentage": 10.5,
    //               "name": "Sales Tax"
    //             },
    //             {
    //               "percentage": 6.5,
    //               "name": "Common Tax"
    //             }
    //           ]
    //         },
    //         {
    //           "product": {
    //             "id": "100000008007"
    //           },
    //           "quantity": 151,
    //           "Discount": 21,
    //           "product_description": "product_description",
    //           "Unit Price": 11,
    //           "line_tax": [
    //             {
    //               "percentage": 11.5,
    //               "name": "Sales Tax"
    //             },
    //             {
    //               "percentage": 7.5,
    //               "name": "Common Tax"
    //             }
    //           ]
    //         }
    //       ],
    //       "Subject": "Subject",
    //       "Excise_Duty": 127.67,
    //       "Shipping_City": "Shipping_City",
    //       "Shipping_Country": "Shipping_Country",
    //       "Shipping_Code": "Shipping_Code",
    //       "Billing_City": "Billing_City",
    //       "Purchase_Order": "Purchase_Order",
    //       "Billing_State": "Billing_State",
    //       "$line_tax": [
    //         {
    //           "percentage": 12.5,
    //           "name": "Sales Tax"
    //         },
    //         {
    //           "percentage": 8.5,
    //           "name": "Common Tax"
    //         }
    //       ],
    //       "Pending": "Pending",
    //       "Shipping_Street": "Shipping_Street"
    //     }
    //   ]
    // }

    let json = CkoJsonObject()!
    json.update("data[0].Owner.id", value: "{{user-id}}")
    json.update("data[0].Deal_Name.id", value: "{{deal-id}}")
    json.update("data[0].Account_Name.id", value: "{{account-id}}")
    json.update("data[0].Quote_Name.id", value: "{{quote-id}}")
    json.update("data[0].Contact_Name.id", value: "{{contact-id}}")
    json.updateNumber("data[0].Discount", numericStr: "127.67")
    json.update("data[0].Description", value: "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.")
    json.update("data[0].Customer_No", value: "Customer_No")
    json.update("data[0].Shipping_State", value: "Shipping_State")
    json.updateNumber("data[0].Tax", numericStr: "127.67")
    json.update("data[0].Billing_Country", value: "Billing_Country")
    json.update("data[0].Carrier", value: "USPS")
    json.update("data[0].Status", value: "Delivered")
    json.updateNumber("data[0].Sales_Commission", numericStr: "127.67")
    json.update("data[0].Due_Date", value: "2018-01-25")
    json.update("data[0].Billing_Street", value: "Billing_Street")
    json.updateNumber("data[0].Adjustment", numericStr: "127.67")
    json.update("data[0].Terms_and_Conditions", value: "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.")
    json.update("data[0].Billing_Code", value: "Billing_Code")
    json.update("data[0].Product_Details[0].product.id", value: "1000000071967")
    json.updateInt("data[0].Product_Details[0].quantity", value: 150)
    json.updateInt("data[0].Product_Details[0].Discount", value: 20)
    json.update("data[0].Product_Details[0].product_description", value: "product_description")
    json.updateInt("data[0].Product_Details[0].\"Unit Price\"", value: 10)
    json.updateNumber("data[0].Product_Details[0].line_tax[0].percentage", numericStr: "10.5")
    json.update("data[0].Product_Details[0].line_tax[0].name", value: "Sales Tax")
    json.updateNumber("data[0].Product_Details[0].line_tax[1].percentage", numericStr: "6.5")
    json.update("data[0].Product_Details[0].line_tax[1].name", value: "Common Tax")
    json.update("data[0].Product_Details[1].product.id", value: "100000008007")
    json.updateInt("data[0].Product_Details[1].quantity", value: 151)
    json.updateInt("data[0].Product_Details[1].Discount", value: 21)
    json.update("data[0].Product_Details[1].product_description", value: "product_description")
    json.updateInt("data[0].Product_Details[1].\"Unit Price\"", value: 11)
    json.updateNumber("data[0].Product_Details[1].line_tax[0].percentage", numericStr: "11.5")
    json.update("data[0].Product_Details[1].line_tax[0].name", value: "Sales Tax")
    json.updateNumber("data[0].Product_Details[1].line_tax[1].percentage", numericStr: "7.5")
    json.update("data[0].Product_Details[1].line_tax[1].name", value: "Common Tax")
    json.update("data[0].Subject", value: "Subject")
    json.updateNumber("data[0].Excise_Duty", numericStr: "127.67")
    json.update("data[0].Shipping_City", value: "Shipping_City")
    json.update("data[0].Shipping_Country", value: "Shipping_Country")
    json.update("data[0].Shipping_Code", value: "Shipping_Code")
    json.update("data[0].Billing_City", value: "Billing_City")
    json.update("data[0].Purchase_Order", value: "Purchase_Order")
    json.update("data[0].Billing_State", value: "Billing_State")
    json.updateNumber("data[0].$line_tax[0].percentage", numericStr: "12.5")
    json.update("data[0].$line_tax[0].name", value: "Sales Tax")
    json.updateNumber("data[0].$line_tax[1].percentage", numericStr: "8.5")
    json.update("data[0].$line_tax[1].name", value: "Common Tax")
    json.update("data[0].Pending", value: "Pending")
    json.update("data[0].Shipping_Street", value: "Shipping_Street")

    http.setRequestHeader("Authorization", value: "{{authorization-token}}")
    http.setRequestHeader("Content-Type", value: "application/json")

    var resp: CkoHttpResponse? = http.postJson3("https://domain.com/crm/v2.1/Sales_Orders", contentType: "application/json", json: json)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: {{authorization-token}}"
	-H "Content-Type: application/json"
	-d '{
	"data": [
		{
			"Owner": {
				"id": "{{user-id}}"
			},
			"Deal_Name": {
				"id": "{{deal-id}}"
			},
			"Account_Name": {
				"id": "{{account-id}}"
			},
			"Quote_Name": {
				"id": "{{quote-id}}"
			},
			"Contact_Name": {
				"id": "{{contact-id}}"
			},
			"Discount": 127.67,
			"Description": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
			"Customer_No": "Customer_No",
			"Shipping_State": "Shipping_State",
			"Tax": 127.67,
			"Billing_Country": "Billing_Country",
			"Carrier": "USPS",
			"Status": "Delivered",
			"Sales_Commission": 127.67,
			"Due_Date": "2018-01-25",
			"Billing_Street": "Billing_Street",
			"Adjustment": 127.67,
			"Terms_and_Conditions": "Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.",
			"Billing_Code": "Billing_Code",
			"Product_Details": [
				{
					"product": {
						"id": "1000000071967"
					},
					"quantity": 150,
					"Discount": 20,
					"product_description": "product_description",
					"Unit Price": 10,
					"line_tax": [
						{
							"percentage": 10.5,
							"name": "Sales Tax"
						},
						{
							"percentage": 6.5,
							"name": "Common Tax"
						}
					]
				},
				{
					"product": {
						"id": "100000008007"
					},
					"quantity": 151,
					"Discount": 21,
					"product_description": "product_description",
					"Unit Price": 11,
					"line_tax": [
						{
							"percentage": 11.5,
							"name": "Sales Tax"
						},
						{
							"percentage": 7.5,
							"name": "Common Tax"
						}
					]
				}
			],
			"Subject": "Subject",
			"Excise_Duty": 127.67,
			"Shipping_City": "Shipping_City",
			"Shipping_Country": "Shipping_Country",
			"Shipping_Code": "Shipping_Code",
			"Billing_City": "Billing_City",
			"Purchase_Order": "Purchase_Order",
			"Billing_State": "Billing_State",
			"$line_tax": [
				{
					"percentage": 12.5,
					"name": "Sales Tax"
				},
				{
					"percentage": 8.5,
					"name": "Common Tax"
				}
			],
			"Pending": "Pending",
			"Shipping_Street": "Shipping_Street"
		}
	]
}'
https://domain.com/crm/v2.1/Sales_Orders

Postman Collection Item JSON

{
  "name": "Sales Orders",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "{{authorization-token}}"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"data\": [\n\t\t{\n\t\t\t\"Owner\": {\n\t\t\t\t\"id\": \"{{user-id}}\"\n\t\t\t},\n\t\t\t\"Deal_Name\": {\n\t\t\t\t\"id\": \"{{deal-id}}\"\n\t\t\t},\n\t\t\t\"Account_Name\": {\n\t\t\t\t\"id\": \"{{account-id}}\"\n\t\t\t},\n\t\t\t\"Quote_Name\": {\n\t\t\t\t\"id\": \"{{quote-id}}\"\n\t\t\t},\n\t\t\t\"Contact_Name\": {\n\t\t\t\t\"id\": \"{{contact-id}}\"\n\t\t\t},\n\t\t\t\"Discount\": 127.67,\n\t\t\t\"Description\": \"Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.\",\n\t\t\t\"Customer_No\": \"Customer_No\",\n\t\t\t\"Shipping_State\": \"Shipping_State\",\n\t\t\t\"Tax\": 127.67,\n\t\t\t\"Billing_Country\": \"Billing_Country\",\n\t\t\t\"Carrier\": \"USPS\",\n\t\t\t\"Status\": \"Delivered\",\n\t\t\t\"Sales_Commission\": 127.67,\n\t\t\t\"Due_Date\": \"2018-01-25\",\n\t\t\t\"Billing_Street\": \"Billing_Street\",\n\t\t\t\"Adjustment\": 127.67,\n\t\t\t\"Terms_and_Conditions\": \"Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.\",\n\t\t\t\"Billing_Code\": \"Billing_Code\",\n\t\t\t\"Product_Details\": [\n\t\t\t\t{\n\t\t\t\t\t\"product\": {\n\t\t\t\t\t\t\"id\": \"1000000071967\"\n\t\t\t\t\t},\n\t\t\t\t\t\"quantity\": 150,\n\t\t\t\t\t\"Discount\": 20,\n\t\t\t\t\t\"product_description\": \"product_description\",\n\t\t\t\t\t\"Unit Price\": 10,\n\t\t\t\t\t\"line_tax\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"percentage\": 10.5,\n\t\t\t\t\t\t\t\"name\": \"Sales Tax\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"percentage\": 6.5,\n\t\t\t\t\t\t\t\"name\": \"Common Tax\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"product\": {\n\t\t\t\t\t\t\"id\": \"100000008007\"\n\t\t\t\t\t},\n\t\t\t\t\t\"quantity\": 151,\n\t\t\t\t\t\"Discount\": 21,\n\t\t\t\t\t\"product_description\": \"product_description\",\n\t\t\t\t\t\"Unit Price\": 11,\n\t\t\t\t\t\"line_tax\": [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"percentage\": 11.5,\n\t\t\t\t\t\t\t\"name\": \"Sales Tax\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"percentage\": 7.5,\n\t\t\t\t\t\t\t\"name\": \"Common Tax\"\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"Subject\": \"Subject\",\n\t\t\t\"Excise_Duty\": 127.67,\n\t\t\t\"Shipping_City\": \"Shipping_City\",\n\t\t\t\"Shipping_Country\": \"Shipping_Country\",\n\t\t\t\"Shipping_Code\": \"Shipping_Code\",\n\t\t\t\"Billing_City\": \"Billing_City\",\n\t\t\t\"Purchase_Order\": \"Purchase_Order\",\n\t\t\t\"Billing_State\": \"Billing_State\",\n\t\t\t\"$line_tax\": [\n\t\t\t\t{\n\t\t\t\t\t\"percentage\": 12.5,\n\t\t\t\t\t\"name\": \"Sales Tax\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"percentage\": 8.5,\n\t\t\t\t\t\"name\": \"Common Tax\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"Pending\": \"Pending\",\n\t\t\t\"Shipping_Street\": \"Shipping_Street\"\n\t\t}\n\t]\n}"
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2.1/Sales_Orders",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "Sales_Orders"
      ]
    },
    "description": "To add new entities to a module."
  },
  "response": [
  ]
}