Через Postman - POST работает, вот исходный код:
Код: Выделить всё
curl --location --request POST 'https://dev-api.checkbox.in.ua/api/v1/receipts/sell' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiQVBJIiwianRpIjoiZGFmZTUyZTctMDUyYi00MjAyLWIyMWItZWVmNDFmZjM5MTUyIiwic3ViIjoiYTVlYmZiMmItYjExMC00M2Q4LTk3NjUtY2MyZTZmMzJlMmJlIiwibmJmIjoxNjQ0NzM5MDg0LCJpYXQiOjE2NDQ3MzkwODR9.SQ9TsyzCL6v0Qq9YORLKmhzkDolshqUVOQbTVw..ST-24' \
--data-raw '{
"goods": [
{
"good": {
"code": "9417",
"name": "Глубоко увлажняющий крем для лица Nature UP Bema Cosmetici,50 мл",
"price": 87000
},
"quantity": 1000,
"is_return": false
}
],
"payments": [
{
"type": "CASH",
"value": 67000
},
{
"type": "CASHLESS",
"value": 20000
}
]
}'
Код: Выделить всё
host = 'https://dev-api.checkbox.in.ua/api/v1/receipts/sell'
! == start postparams =================================================
! create GOOD group ==========================================
gds &= json::CreateArray()
LOOP i# = 1 TO RECORDS(goodsQ) !
GET(goodsQ,i#)
!- create an array item
gditem &= json::CreateObject()
! fill group GOOD ==========
pGoods_m:id = goodsQ:good_id
GET(pGoods_m,pGoods_m:primkey)
! ==========================
!- add it to the array gds
gds.AddItemToArray(gditem)
gd &= json::CreateObject()
gd.AddStringToObject('code', pGoods_m:code)
gd.AddStringToObject('name', pGoods_m:name)
gd.AddNumberToObject('price', pGoods_m:price * 100)
!- add objects to the item
gditem.AddItemToObject('good', gd)
gditem.AddNumberToObject('quantity', goodsQ.quantity * 1000)
gditem.AddItemToObject('is_return', json::CreateFalse())
END
paym &= json::CreateArray()
SET(pPaym_m)
LOOP !
NEXT(pPaym_m); IF ERRORCODE() THEN BREAK END
!- create an array item
pitem &= json::CreateObject()
paym.AddItemToArray(pitem)
pitem.AddStringToObject('type', pPaym_m.type)
pitem.AddNumberToObject('value', pPaym_m.value * 100)
END
! create GOODS queue ==========================================
!create root object
root &= json::CreateObject()
!add a string to root
root.AddItemToObject('goods', gds)
! create paym
root.AddItemToObject('payments', paym)
CASE xReturn_
OF 1
root.AddItemToObject('technical_return', json::CreateTrue())
ELSE
root.AddItemToObject('technical_return', json::CreateFalse())
END
! == end postparams =================================================
postparams = root.ToString()
curl.Init()
curl.AddHttpHeader('Content-Type: application/json') !- or 'Content-Type: text/json'
curl.AddHttpHeader('Authorization: Bearer '& CLIP(SetCBX:jwtToken))
curl.AddHttpHeader('Accept-Charset: utf-8')
curl.SetHttpHeaders()
curl.SetCustomRequest('POST')
curl.SetHttpGET(TRUE)
! if ssl req'd
curl.SetSSLVerifyHost(false) ! do not verify host name
curl.SetSSLVerifyPeer(FALSE) ! verify peer
res = curl.SendRequestStr(host, postparams, respBuffer)
IF res = CURLE_OK
! === cJSON ======================================
jsonFactory.codePage = CP_ACP !- convert utf8 to ascii (active code page)
root &= jsonFactory.Parse(respBuffer)
IF root &= NULL
MESSAGE('Syntax error near: '& jsonFactory.GetError() &'|at position '& jsonFactory.GetErrorPosition())
END
! получить код статуса запроса
codeCurl# = curl.GetResponseCode() ! Получить код ответа сервиса на запрос
If codeCurl# = 201
MESSAGE('Внимание (201) - чек отправлен!')
ELSIf codeCurl# = 422
MESSAGE(root.ToString(TRUE),'Внимание (422)')
ELSE
! Ошибка
MESSAGE(root.ToString(TRUE),'Ошибка: '& codeCurl#)
END
root.Delete()
ELSIF res = -1
MESSAGE('Cannot open local file', 'libcurl', ICON:Exclamation)
ELSE
MESSAGE('SendRequest failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
Не знаю как увидеть и проверить отправляемый запрос целиком, есть ли возможность в libcurl показать отправляемое сообщение в исходном (curl) виде, как в Postman?