Body format for Stripe POST operations

stripe charge api
stripe post v1 charges
stripe api
stripe 502
stripe webhooks
expandable stripe
how to authenticate stripe
stripe payment methods

I'm accessing the stripe API directly with the REST API (not using a library) but, surprisingly, I can't find documentation on the appropriate body format post data.

Does Stripe expect JSON or form-encoded pairs?

You need to post raw data like key-value pair. (No Json)

e.g. key1=value1&key2=value2

Make sure you include following in header Content-Type = application/x-www-form-urlencoded

Stripe API Reference, as long as you're doing under $1 million in volume per year. This rate varies country to country, but it's always flat. 1. Now let us add a Request Body to our POST request. Every Endpoint will be document with what kind of Method type and the format of body that it expects. Let us see what body this request expects and how to add it. For that click on Body tab. 2. Click on raw and select format type as JSON, since we have to send in correct format which the server expects.

Here is the sample of the curl code to Nodejs I am working on a similar problem

as you know we can't send JSON for the "post" method it must be URL encoded

here is the sample provided by stripe

curl \
>   -u stripe_key_here: \
>   -d success_url="" \
>   -d cancel_url="" \
>   -d "payment_method_types[]=card" \
>   -d "line_items[][name]=T-shirt" \
>   -d "line_items[][description]=Comfortable cotton t-shirt" \
>   -d "line_items[][amount]=1500" \
>   -d "line_items[][currency]=usd" \
>   -d "line_items[][quantity]=2"

-u means authorization which we provide in the headers -d means body of the url

sample code in node js

const fetch = require("node-fetch");
const stripeKey = process.env.STRIPE_KEY;

async function getCheckoutID() {
  try {
    const endpoint = "";

    const query = objToQuery({
      success_url: "",
      cancel_url: "",
      "payment_method_types[]": "card",
      "line_items[][name]": "T-shirt",
      "line_items[][description]": "Comfortable cotton t-shirt",
      "line_items[][amount]": 1500,
      "line_items[][quantity]": 1,
      "line_items[][currency]": "usd"

    // enpoint => ""
    // query => "?key=value&key1=value1"
    const URL = `${endpoint}${query}`;

    const fetchOpts = {
      method: "post",
      headers: {
        "Authorization": `Bearer ${stripeKey}`,
        "Content-Type": "application/x-www-form-urlencoded"
    const checkout = await getJSON(URL, fetchOpts);

    console.log("CHECKOUT OBJECT : " , checkout);

    return checkout;
  catch(e) {

// hepler functions

// instead of using fetch
// getJSON will make it readable code
async function getJSON(url, options) {
  const http = await fetch(url, options);
  if (!http.ok) {
    throw new Error("ERROR STATUS IS NOT OK :");
  return http.json();

// convert JS object to url query
// {key:"value" , key1: "value1"} to "key=value&key1=value1"
function objToQuery(obj) {
  const query = Object.keys(obj).map( k => `${k}=${obj[k]}`).join("&");
  return query.length > 0 ? `?${query}` : "";

Stripe vs PayPal: Who should you choose?, occurrence, Stripe POSTs the webhook data to your endpoint in JSON format. 'json' # Using Sinatra post '/webhook' do payload = event  The webhook endpoint uses the event details to take any required actions, such as indicating that an order should be fulfilled. When to use webhooks Many events that occur within a Stripe account have synchronous results–immediate and direct–to an executed request.

Here is an example cURL charge using a test card:

curl -u your_test_key: -d card[number]=4000056655665556 -d card[exp_month]=11 -d card[exp_year]=2020 -d amount=100 -d currency=eur -d description="Stripe cUrl charge test"

Exchange your_test_key with your stripe test key. Remember to keep the : after your key to not get asked for a password.

How to delay payments and hold funds with Stripe, events by checking the type field of the event object sent in the request body. 4242 post '/webhook' do payload = event = nil begin event  Stripe API Reference. We challenge you to find a discussion about the best API reference docs that doesn’t include Stripe. Spoiler alert: there isn’t one. The Stripe API documentation, or the Stripe API Reference, is a work of art. It features a sleek and cool two-panel design, with explanations written in plain English on the left and

Form encoded pairs

The docs for cURL provide good examples. They're just feeding form encoded key/value pairs via the -d switch via cURL on the command line. Just make sure you use your test secret key so you don't screw up any live data. Then you can play around all you want.

The returned data is JSON.

How Does Stripe Work?, curl \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d amount=999 \ -d currency=usd \ -d description="Example charge" \ -d  Found the following information on another post. AR 670-1, Ch 28-28 (12) One overseas service bar is authorized for each 6-month period of Federal service as a member of a U.S. Service participating in Operation Enduring Freedom, the CENTCOM area of operations, or under the control of the Combatant Commander, CENTCOM, from 19 September 2001

Build a webhook endpoint, For example, the API servers might return a 401 if an invalid API key was provided, For a POST operation using an idempotency key, as long as an API method if it should retry based solely on a status code or content in the response body. The type of the body of the request is indicated by the Content-Type header. The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.

Handle payment events, The webhook endpoint has an associated URL (e.g.,​webhooks). The Stripe notifications are Event objects. This Event object contains all  Accept a payment Charges API. Accept online payments from your U.S. and Canadian customers. The Charges API is an older payments API that does not handle bank requests for card authentication. Try our new payments APIs and integrations instead.

The Charges API, The following example shows how to handle both events: require 'sinatra' require 'stripe' post '/webhook' do payload = sig_header  Email receipts. Send payment or refund receipts automatically. Receipts in test mode. Receipts for payments created using your test API keys are not sent automatically. Instead, you can view or manually send a receipt using the Dashboard. Stripe can automatically send email receipts after a successful payment, or when you refund one.

  • Yes. You basically have to look at the curl examples and deduce that the body format is x-www-form-urlencoded.
  • Thanks but i'm not familiar with cURL so its unclear with -d means. It sounds like you're saying the POST is always form encoded and the response is JSON. But if that is the case... how are users to POST the metadata element which would represent a child object ALSO containing key/value pairs... i would think you'd need JSON for that nesting of a child object.
  • FYI, i just noticed on that the form-encoded format is: metadata[key]=value