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.
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:
DATA
json JSONClass
str StringTheory
payload &STRING
payloadSize LONG
!WebClient NetWebClient ! Added as Extension to the procedure !
CODE
WebClient.Start()
WebClient.HeaderOnly = FALSE
WebClient.SetAllHeadersDefault()
WebClient.SetContentType('json')
WebClient.SetAccept('json')
WebClient.AsyncOpenTimeOut = 300
json.Start()
! 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.SetContentType('multipart')
WebClient.Post( 'URL-TO-POST-DATA-TO' )
DISPOSE(payload)
Are you sure you’re using the API correctly?
According to this…
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
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?
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\”}’
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