Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
error in creating charge coinbase commerce through post request

i am trying to create a charge in coinbase commerce

const query = {
    name: 'The Sovereign Individual',
    description: 'Mastering the Transition to the Information Age',
    local_price: {
        amount: '100.00',
        currency: 'USD',
    },
    pricing_type: 'fixed_price',
    metadata: {
        customer_id: 'id_1005',
        customer_name: 'Satoshi Nakamoto',
    },
    redirect_url: 'https://charge/completed/page',
    cancel_url: 'https://charge/canceled/page',
};
const opts = {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'X-CC-Api-Key': '6225fe4d-f9a8-498f-8085-11dea4212316',
        'X-CC-Version': '2018-03-22',
    },
    body: JSON.stringify({ query }),
};
const res = fetch('https://api.commerce.coinbase.com/charges', opts).then(
    (res) => res.json()
);

this is my current post request but it is showing me error , i believe it is format issue , but can anyone help me in this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to provide the error message you got before asking for help, either way after looking at your code i found some issues.

at this part

const res = fetch('https://api.commerce.coinbase.com/charges', opts).then(
    (res) => res.json()
);

you cannot assign the result of fetch to a constant becuause you're using .then to handle the promise and the returning value is passed to the callback, second res.json() returns a promise as well, and you're not handling it.

This would solve the above stated problems

const res = await fetch('https://api.commerce.coinbase.com/charges', opts);
const jsonRes = await res.json();
// using async await

if you don't wanna use async/await

fetch('https://api.commerce.coinbase.com/charges', opts)
.then(res => res.json())
.then(jsonRes => console.log(jsonRes));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda