Help Nettalk, PUT - Bad Request

Tags: #<Tag:0x00007fc0d70b1cc0>


I’m using Nettalk to change records in REST API, added record with POST and when I change it with PUT it presents error: 400 - Bad Request.
I’m using npostman for testing and it works perfectly, below the information used with NetTalk.

json - POST - OK

json - PUT - Error 400
“cidade”:“cacapava do sul”,

net1.ContentType = ‘application/json’
net1.CustomHeader = ‘ApplicationToken: e00bf526-0196-11eb-94ad-d207fc3b6205<13,10>CompanyToken: ea69b414-0195-11eb-aec6-0e34752640b6’
net1.HeaderOnly = 0
net1.ConnectionKeepAlive = 0
net1.put(‘’, ‘{{“cidade”:“cacapava do sul”,“tipo”:“J”,“razao_social”:“f2e45931e8a24654”}’)

Hello JLHenriques,

I did something similar, POST Json data to a GraphQL API Endpoint. I’ve used jFiles to create the JSON as there was a lot of nested data to process it within a single CString variable. Also I need to ensure UTF8 encoded data to be send, so StringTheory did the trick.

Here the code that worked for me:

  json                 JSONClass
  str                  StringTheory
  payload              &STRING
  payloadSize          LONG
  !WebClient           NetWebClient   ! Added as Extension to the procedure !

  WebClient.HeaderOnly = FALSE
  WebClient.AsyncOpenTimeOut = 300

  ! Create your JSON data
  json.SaveString(str, FALSE)
  payload &= str.AnsiToUtf8(str.GetValuePtr(), payloadSize, st:CP_ISO_8859_1)
  WebClient.SetValue('variables', payload, FALSE, 'json')
  WebClient.SetValue('query', 'mutation () {{ }', FALSE, 'json')
  WebClient.Post( 'URL-TO-POST-DATA-TO' )

Best regards

My problem is with the PUT method, GET/POST worked.

Are you sure you’re using the API correctly?
According to this…,sc#reference/0/clientes/alterar-um-cliente
You change a Customer record using the ID and PUT
If you just pass in the City, Type and Corporate Name then you’re not using the unique indentifier that the system uses to locate that record to change.

Error 400 on the PUT just means it’s not in the correct format

i generate a json file with the information, curl.exe or npostman it works.

curl --include --request PUT --header “Content-Type: application/json” --header “ApplicationToken: e00bf526-0196-11eb-94ad-d207fc3b6205” --header “CompanyToken: ea69b414-0195-11eb-aec6-0e34752640b6” --data-binary “@c:\temp\0000000968.json” --output “c:\temp\0000000968_ret.txt”

your code looks fine, and comparable to the Curl example, but begs the question;
What is in c:\temp\0000000968.json ?
How does that compare to your json data you are sending?


Hi Bruce,

The json file contains update below, “tipo” and “razao_social” are required, the others only when changed.



I also work with an GraphQL API and I need to quote/escape the quotes with a backslash,
like " = \" for string data (not for the labels!)

That means it should look like this:

net1.put(‘ ’, ‘{{“cidade”:\“cacapava do sul\”,“tipo”:\“J\”,“razao_social”:\“f2e45931e8a24654\”}’)

And if the value of “tipo” is not a string (tipo:J instead of tipo:‘J’) then
“tipo”:\“J\” sould be ,“tipo”:“J” as it was.

BTW the API I´m working with would need the labels including the ‘:’ and would look like this:
‘{{cidade:\“cacapava do sul\” tipo:J razao_social:\“f2e45931e8a24654\”}’

Hi JL,

Clearly there is some minor difference in play here that I’ve not been able to glean from your posts.
I recommend you come to one of the user group webinars, on a Thursday, so I can show you how to debug this, and also determine what is the magic detail you are forgetting to tell me :slight_smile: