Web Connection
Calling an API with simple text in the body of the request
Gravatar is a globally recognized avatar based on your email address. Calling an API with simple text in the body of the request
  Richard Kaye
  All
  Apr 11, 2024 @ 08:23am

Hi Rick,

Whilst I poke at this on my own I figure I'll ask the n00nb question. I've got a decent grip on calling external APIs using json as a post key in the request along with the auth in the header. Now I'm working with an endpoint which takes a simple string. I still need the auth in the header but I don't need to build some fancy VFP object, run it through a serializer, etc. What is the recommended way to put a simple string into the body of the request without all that serialization/deserialization stuff?

TIA

Gravatar is a globally recognized avatar based on your email address. re: Calling an API with simple text in the body of the request
  Richard Kaye
  Richard Kaye
  Apr 11, 2024 @ 09:21am

OK. Just to add some more color commentary here, I've got a wrapper that pushes all my external API calls through CallService. If I use wwhttp.post() instead I've got it working. In any case I'll appreciate any thoughts you care to share about this.

Gravatar is a globally recognized avatar based on your email address. re: Calling an API with simple text in the body of the request
  Rick Strahl
  Richard Kaye
  Apr 11, 2024 @ 12:18pm

Just send a raw post.

lcRawData = "Hello cruel World!"
loHttp.cContentType = "plain/text"
lcResult = loHttp.Post(lcUrl, lcRawData)

Gravatar is a globally recognized avatar based on your email address. re: Calling an API with simple text in the body of the request
  Richard Kaye
  Rick Strahl
  Apr 12, 2024 @ 02:05am

Thanks! Pretty much where I landed but I do need to change the content type.

Gravatar is a globally recognized avatar based on your email address. re: Calling an API with simple text in the body of the request
  Rick Strahl
  Richard Kaye
  Apr 12, 2024 @ 10:59am

The content type only matters if the server cares about it. Depends on the API...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Calling an API with simple text in the body of the request
  Richard Kaye
  Rick Strahl
  Apr 12, 2024 @ 11:41am

It cared. The wrong way... I took that out. 😃 Thanks again.

© 1996-2024