CreatePayment API on my backend

New to working with payment processing so I’m a bit confused. Working in Sandbox mode.

I’m working on adding createPayment api to my backend and deploying it to firebase functions.
when I run the request in postman using: ```

everything works just fine. 

when i replace it with my firebase deployed endpoint:
using the same authorization, headers, and body i always get a 401 error.

const baseUrl = “”;

    // Construct the API endpoint and request payload
    const endpoint = "/v2/payments";
    const url = baseUrl + endpoint;
    const requestData = {
      idempotency_key: idempotencyKey,
      source_id: sourceId,
      amount_money: {
      autocomplete: true,
      accept_partial_authorization: false,

    // Make a POST request to create a payment
    const fetchOptions = {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${accessToken}`,
        "Content-Type": "application/json",
        "Square-Version": "2023-08-16",
      body: JSON.stringify(requestData),

    const apiResponse = await fetch(url, fetchOptions);
    const responseData = await apiResponse.json();
i also have my accessToken just left it out for security reasons.

Are there any additional error messages? A 401 is an unauthorized error which would indicate that some credential isn’t set correctly. :slight_smile:

Hey Bryan thanks for reaching out!

Sadly this is the only error message I have:

401 Unauthorized

Error: Unauthorized

Your client does not have permission to the requested URL /createPayment.

I thought it would be a firebase AUTH issue but all my other endpoints work just fine.
If it helps I’m using node.js/typescript and deploying as a firebase function.

From my understanding i just need to use the payments API on my backend and pass:
accessToken, sourceId, idempotencyKey, amount, and currency for the createPayment endpoint that I deployed to firebase functions?

Yes, that’s correct. That’s all thats required. What’s your application ID? :slight_smile:

My application ID is: sandbox-sq0idb-5UPoI3FXXBlFwZxgmqn71g