Libcurl response 415 Unsupported Media Type

Hi all,

I am (probably) stuck on a syntax issue.

Attached is a working postman example. When I submit using the code below I get an http code 415 (Unsupported Media Type) back.

What am I doing wrong?

Thanks in advance.

Henk Ouwejan

ShipmentDPD PROCEDURE

res            CURLcode
resCode        SHORT

  CODE
  ?TEXT:Response{PROP:Text} = ''
  json.Start()
  json.LoadFile('c:\temp\boekuwzending.json') ! message in json format
  json.savestring(st,True)
  ?TEXT:Request{PROP:Text} = st.GetValue()
  curl.init()
  curl.useSSL(CURLUSESSL_ALL)
  curl.setSSLVerifyPeer(False)
  curl.setSSLVerifyHost(False)
  curl.setCustomRequest('POST')
  curl.addHttpHeader('Content-Type: application/json')
  curl.addHttpHeader('Accept: application/json')
  curl.addHttpHeader('Authorization: Bearer '&CLIP(BUZ:token))
  curl.setHttpHeaders()
  res = curl.sendRequest(CLIP(BUZ:url)&'/shipments',st.GetValue(),ResponseBuffer)
  resCode = curl.GetResponseCode()
  IF res = CURLE_OK
    message('Response: '&resCode,'debug')
    st.SetValue(ResponseBuffer)
    ?TEXT:Response{PROP:Text} = st.GetValue()
    IF json.GetValueByName('error') = 'false'
      message('OK','debug')
    ELSE
      MESSAGE('Resultaat: '&resCode,'debug')    ! json.GetValueByName('error'))
      ?TEXT:Response{PROP:Text} = ResponseBuffer
    END
  ELSE
   MESSAGE('Geen juiste response: '&res,'Fout',ICON:Hand)
  END
  DISPLAY
  json.Free()

Working Postman file:

curl --location ‘https://api.boekuwzending.com/shipments
–header ‘Content-Type: application/json’
–header ‘Authorization: Bearer xxx’
–data-raw ‘{
“invoiceReference”: “81”,
“transportType”: “road_transport”,
“shipTo”: {
“contact”: {
“name”: “Cees Vegers”,
“emailAddress”: “[email protected]”,
“phoneNumber”: “0612345678”,
“company”: “”
},
“address”: {
“number”: “265”,
“street”: “Bennebroekerweg”,
“numberAddition”: “”,
“addressLine1”: “”,
“addressLine2”: “”,
“postcode”: “1435CJ”,
“city”: “Nieuw-Vennep”,
“country”: “NL”,
“privateAddress”: 1,
“forkliftOrLoadingDockAvailable”: “”,
“accessibleWithTrailer”: “”
}
},
“dispatch”: {
“instructions”: “”,
“reference”: “”,
“timeWindow”: {
“begin”: null,
“end”: null
},
“vatNumber”: “”,
“eoriNumber”: “”,
“date”: “2025-06-04”
},
“items”: [
{
“quantity”: 1,
“type”: “package”,
“dimensions”: {
“length”: 1,
“height”: 10,
“width”: 10
},
“weight”: 1,
“description”: “Pakket”,
“value”: null,
“tariffNumber”: “”,
“countryOfOrigin”: “”,
“customerReference”: “”
}
],
“service”: “dpd-classic”
}’

I haven’t looked up how to do this with Libcurl and I’m not familiar enough with it to spot any obvious code errors, but the first thing I would be checking is that I actually had the JSON code and that I was using the correct method to attach that JSON to the request.

Have you tried using the --libcurl example.c command line option with your working Postman file? This will create a working C program with all the curl commands. These can usually be translated to libcurl calls.