Sample code for 30+ languages & platforms
Xbase++

MYOB: Update a Category

See more MYOB Examples

Sends a PUT to update a category.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oSbRequestBody
LOCAL oResp
LOCAL nRespStatusCode

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

//  Implements the following CURL command:

//  curl --request PUT "https://ar1.api.myob.com/accountright/c06778dd-4371-4a83-975f-522df65d7574/GeneralLedger/Category/{{category_id}}" \
//    --header "Authorization: Bearer ACCESS_TOKEN" \
//    --header "x-myobapi-key: This is your API Key" \
//    --header "x-myobapi-version: v2" \
//    --header "Accept-Encoding: gzip,deflate" \
//    --data "{
//              \"UID\": \"20b483b2-9a89-4793-b8c3-2da1a6284e1f\",
//              \"DisplayID\": \"Postman001\",
//              \"Name\": \"Postman sample\",
//              \"Description\": \"This has been updated via Postman\",
//              \"IsActive\": true,
//              \"RowVersion\": \"-8858580467037765632\"
//          }"

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

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

//  {
//    "UID": "20b483b2-9a89-4793-b8c3-2da1a6284e1f",
//    "DisplayID": "Postman001",
//    "Name": "Postman sample",
//    "Description": "This has been updated via Postman",
//    "IsActive": true,
//    "RowVersion": "-8858580467037765632"
//  }

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("UID", "20b483b2-9a89-4793-b8c3-2da1a6284e1f")
oJson:UpdateString("DisplayID", "Postman001")
oJson:UpdateString("Name", "Postman sample")
oJson:UpdateString("Description", "This has been updated via Postman")
oJson:UpdateBool("IsActive", 1)
oJson:UpdateString("RowVersion", "-8858580467037765632")

oHttp:SetRequestHeader("Authorization", "Bearer ACCESS_TOKEN")
oHttp:SetRequestHeader("x-myobapi-key", "This is your API Key")
oHttp:SetRequestHeader("Accept-Encoding", "gzip,deflate")
oHttp:SetRequestHeader("x-myobapi-version", "v2")

oSbRequestBody := CreateObject("Chilkat.StringBuilder")
oJson:EmitSb(oSbRequestBody)

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpSb("PUT", "https://ar1.api.myob.com/accountright/c06778dd-4371-4a83-975f-522df65d7574/GeneralLedger/Category/{{category_id}}", oSbRequestBody, "utf-8", "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJson:destroy()
    oSbRequestBody:destroy()
    oResp:destroy()
    RETURN
ENDIF

nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode != 200)
    ? "Response Header:"
    ? oResp:Header
    ? "Response Body:"
    ? oResp:BodyStr
    ? "Failed."
    oHttp:destroy()
    oJson:destroy()
    oSbRequestBody:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "Success."

oHttp:destroy()
oJson:destroy()
oSbRequestBody:destroy()
oResp:destroy()