West Wind Internet and Client Tools
wwHTTP - Adding a numeric post key value
Gravatar is a globally recognized avatar based on your email address. wwHTTP - Adding a numeric post key value
  Carl Chambers
  All
  Nov 26, 2022 @ 12:26pm

Hey Rick,

I'm trying to make a request to the Stripe API to fetch a list of items.
The number of items returned can be restricted to value passed in the limit parameter.

So I used...

oHTTP.AddPostKey("limit",lnLimit)

I get an error indicating that "limit" is an unknown parameter but I know that it is a valid parameter.
The request POST body shown in the Stripe request log shows this.

{
  "limit": "50"
}

The limit parameter is being received as a string rather than as a number. So far, I have no definitive answer from Stripe if the data type is causing the error but in case this is the problem...
Is there a way to add a post key in such a way that the post body becomes this instead?

{
  "limit": 50
}

BTW, I did try

lcJSON = [{ "limit": ] + TRANSFORM(lnLimit) + [ }]
oHTTP.AddPostKey("",lcJSON)

That gave me a parameter_missing error and there was no request POST body shown in the request log.

Thanks, Carl

Gravatar is a globally recognized avatar based on your email address. re: wwHTTP - Adding a numeric post key value
  Rick Strahl
  Carl Chambers
  Nov 26, 2022 @ 05:10pm

Values passed to AddPostKey() have to be of type string...

oHTTP.AddPostKey("limit",TRANSFORM(lnLimit))

But what you're posting here doesn't look like a HTTP form variables (which is what the above does), but rather a JSON document. You have to build the JSON string and then post that instead:

lcJson = "{ limit: " + TRANS(lnLimit) + " }"
Response.ContentType = "application/json"
oHttp.AddPostKey(lcJson)

Or if more complex use wwJsonSerializer to build up the JSON.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwHTTP - Adding a numeric post key value
  Carl Chambers
  Rick Strahl
  Nov 26, 2022 @ 08:22pm

Hi Rick,

I was barking up the wrong tree.
Because it's a REST API, the same URL is used for listing all items as for adding an item and "limit" is not a valid parameter for a POST operation. Once I explicitly set the http verb to GET, it worked fine.
Sorry for the bother.

Thanks, Carl

© 1996-2024