Chilkat Online Tools

PureBasic / PrestaShop Webservice Product Resource A-Z / 5 - Get stock available

Back to Collection Items

IncludeFile "CkJsonObject.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

    CkHttp::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "{{webservice_key}}")
    CkHttp::setCkPassword(http, "password")

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

    CkJsonObject::ckUpdateInt(queryParams,"filter[id_product]",1)
    CkJsonObject::ckUpdateString(queryParams,"display","full")
    CkJsonObject::ckUpdateString(queryParams,"output_format","JSON")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://localhost:8080/api/stock_availables",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

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



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)


    ProcedureReturn
EndProcedure

Curl Command

curl -G -d "filter[id_product]=1"
	-d "display=full"
	-d "output_format=JSON"
	-u '{{webservice_key}}:password'
https://localhost:8080/api/stock_availables

Postman Collection Item JSON

{
  "name": "5 - Get stock available",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{webservice_url}}/api/stock_availables?filter[id_product]={{product_id}}&display=full&output_format=JSON",
      "host": [
        "{{webservice_url}}"
      ],
      "path": [
        "api",
        "stock_availables"
      ],
      "query": [
        {
          "key": "filter[id_product]",
          "value": "{{product_id}}"
        },
        {
          "key": "display",
          "value": "full"
        },
        {
          "key": "output_format",
          "value": "JSON"
        }
      ]
    }
  },
  "response": [
  ]
}