Chilkat Online Tools

PureBasic / Zoho CRM REST APIs / Invoices

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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}}"
    ;       },
    ;       "Account_Name": {
    ;         "id": "{{account-id}}"
    ;       },
    ;       "Sales_Order": {
    ;         "id": "{{sales-order-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.",
    ;       "Shipping_State": "Shipping_State",
    ;       "Tax": 127.67,
    ;       "Invoice_Date": "2018-01-25",
    ;       "Billing_Country": "Billing_Country",
    ;       "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"
    ;         }
    ;       ],
    ;       "Shipping_Street": "Shipping_Street"
    ;     }
    ;   ]
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"data[0].Owner.id","{{user-id}}")
    CkJsonObject::ckUpdateString(json,"data[0].Account_Name.id","{{account-id}}")
    CkJsonObject::ckUpdateString(json,"data[0].Sales_Order.id","{{sales-order-id}}")
    CkJsonObject::ckUpdateString(json,"data[0].Contact_Name.id","{{contact-id}}")
    CkJsonObject::ckUpdateNumber(json,"data[0].Discount","127.67")
    CkJsonObject::ckUpdateString(json,"data[0].Description","Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.")
    CkJsonObject::ckUpdateString(json,"data[0].Shipping_State","Shipping_State")
    CkJsonObject::ckUpdateNumber(json,"data[0].Tax","127.67")
    CkJsonObject::ckUpdateString(json,"data[0].Invoice_Date","2018-01-25")
    CkJsonObject::ckUpdateString(json,"data[0].Billing_Country","Billing_Country")
    CkJsonObject::ckUpdateString(json,"data[0].Status","Delivered")
    CkJsonObject::ckUpdateNumber(json,"data[0].Sales_Commission","127.67")
    CkJsonObject::ckUpdateString(json,"data[0].Due_Date","2018-01-25")
    CkJsonObject::ckUpdateString(json,"data[0].Billing_Street","Billing_Street")
    CkJsonObject::ckUpdateNumber(json,"data[0].Adjustment","127.67")
    CkJsonObject::ckUpdateString(json,"data[0].Terms_and_Conditions","Design your own layouts that align your business processes precisely. Assign them to profiles appropriately.")
    CkJsonObject::ckUpdateString(json,"data[0].Billing_Code","Billing_Code")
    CkJsonObject::ckUpdateString(json,"data[0].Product_Details[0].product.id","1000000071967")
    CkJsonObject::ckUpdateInt(json,"data[0].Product_Details[0].quantity",150)
    CkJsonObject::ckUpdateInt(json,"data[0].Product_Details[0].Discount",20)
    CkJsonObject::ckUpdateString(json,"data[0].Product_Details[0].product_description","product_description")
    CkJsonObject::ckUpdateInt(json,"data[0].Product_Details[0]." + Chr(34) + "Unit Price" + Chr(34),10)
    CkJsonObject::ckUpdateNumber(json,"data[0].Product_Details[0].line_tax[0].percentage","10.5")
    CkJsonObject::ckUpdateString(json,"data[0].Product_Details[0].line_tax[0].name","Sales Tax")
    CkJsonObject::ckUpdateNumber(json,"data[0].Product_Details[0].line_tax[1].percentage","6.5")
    CkJsonObject::ckUpdateString(json,"data[0].Product_Details[0].line_tax[1].name","Common Tax")
    CkJsonObject::ckUpdateString(json,"data[0].Product_Details[1].product.id","100000008007")
    CkJsonObject::ckUpdateInt(json,"data[0].Product_Details[1].quantity",151)
    CkJsonObject::ckUpdateInt(json,"data[0].Product_Details[1].Discount",21)
    CkJsonObject::ckUpdateString(json,"data[0].Product_Details[1].product_description","product_description")
    CkJsonObject::ckUpdateInt(json,"data[0].Product_Details[1]." + Chr(34) + "Unit Price" + Chr(34),11)
    CkJsonObject::ckUpdateNumber(json,"data[0].Product_Details[1].line_tax[0].percentage","11.5")
    CkJsonObject::ckUpdateString(json,"data[0].Product_Details[1].line_tax[0].name","Sales Tax")
    CkJsonObject::ckUpdateNumber(json,"data[0].Product_Details[1].line_tax[1].percentage","7.5")
    CkJsonObject::ckUpdateString(json,"data[0].Product_Details[1].line_tax[1].name","Common Tax")
    CkJsonObject::ckUpdateString(json,"data[0].Subject","Subject")
    CkJsonObject::ckUpdateNumber(json,"data[0].Excise_Duty","127.67")
    CkJsonObject::ckUpdateString(json,"data[0].Shipping_City","Shipping_City")
    CkJsonObject::ckUpdateString(json,"data[0].Shipping_Country","Shipping_Country")
    CkJsonObject::ckUpdateString(json,"data[0].Shipping_Code","Shipping_Code")
    CkJsonObject::ckUpdateString(json,"data[0].Billing_City","Billing_City")
    CkJsonObject::ckUpdateString(json,"data[0].Purchase_Order","Purchase_Order")
    CkJsonObject::ckUpdateString(json,"data[0].Billing_State","Billing_State")
    CkJsonObject::ckUpdateNumber(json,"data[0].$line_tax[0].percentage","12.5")
    CkJsonObject::ckUpdateString(json,"data[0].$line_tax[0].name","Sales Tax")
    CkJsonObject::ckUpdateNumber(json,"data[0].$line_tax[1].percentage","8.5")
    CkJsonObject::ckUpdateString(json,"data[0].$line_tax[1].name","Common Tax")
    CkJsonObject::ckUpdateString(json,"data[0].Shipping_Street","Shipping_Street")

    CkHttp::ckSetRequestHeader(http,"Authorization","{{authorization-token}}")
    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckEmitSb(json,sbRequestBody)

    resp.i = CkHttp::ckPTextSb(http,"PUT","https://domain.com/crm/v2.1/Invoices/{{record-id}}",sbRequestBody,"utf-8","application/json",0,0)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbRequestBody)


    ProcedureReturn
EndProcedure

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Authorization: {{authorization-token}}"
	-H "Content-Type: application/json"
	-d '{
	"data": [
		{
			"Owner": {
				"id": "{{user-id}}"
			},
			"Account_Name": {
				"id": "{{account-id}}"
			},
			"Sales_Order": {
				"id": "{{sales-order-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.",
			"Shipping_State": "Shipping_State",
			"Tax": 127.67,
			"Invoice_Date": "2018-01-25",
			"Billing_Country": "Billing_Country",
			"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"
				}
			],
			"Shipping_Street": "Shipping_Street"
		}
	]
}'
https://domain.com/crm/v2.1/Invoices/{{record-id}}

Postman Collection Item JSON

{
  "name": "Invoices",
  "request": {
    "method": "PUT",
    "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\"Account_Name\": {\n\t\t\t\t\"id\": \"{{account-id}}\"\n\t\t\t},\n\t\t\t\"Sales_Order\": {\n\t\t\t\t\"id\": \"{{sales-order-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\"Shipping_State\": \"Shipping_State\",\n\t\t\t\"Tax\": 127.67,\n\t\t\t\"Invoice_Date\": \"2018-01-25\",\n\t\t\t\"Billing_Country\": \"Billing_Country\",\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\"Shipping_Street\": \"Shipping_Street\"\n\t\t}\n\t]\n}"
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2.1/Invoices/{{record-id}}",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "Invoices",
        "{{record-id}}"
      ]
    },
    "description": "To update existing entities in the module."
  },
  "response": [
  ]
}