Getting error while creating peyment(Stripe) - request

I'm using this code to create payment(Stripe) in the tab Pre-request script
pm.sendRequest({
url: 'https://api.stripe.com/v1/tokens',
method: 'POST',
headers: {
'Authorization': 'Bearer pk_test_...',
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
'card[number]': 2223003122003222,
'card[exp_month]': 12,
'card[exp_year]': 2020,
'card[cvc]': 123
}
And getting this error:
You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY').
everything works as a separate request

In my case, I had my dotenv import come after I was calling my secret key.
const stripe = require("stripe")(process.env.STRIPE_SECRET);
require ("dotenv").config();
Reversing those two lines of code was what I needed to do.
require ("dotenv").config();
const stripe = require("stripe")(process.env.STRIPE_SECRET);

I think you're after something like this:
pm.sendRequest({
url: 'https://api.stripe.com/v1/tokens',
method: 'POST',
header: {
'Authorization': 'Bearer pk_test_......',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: {
mode: 'urlencoded',
urlencoded: [
{ key: "card[number]", value: 2223003122003222 },
{ key: "card[exp_month]", value: 12 },
{ key: "card[exp_year]", value: 2020 },
{ key: "card[cvc]", value: 123 },
]
}
})
Your issue was around the headers key as it should be header. Also, the way the payload was written seemed like it would error(?). I tried this code locally and saw the response back from Stripe.
You might want to change the token credentials now that you've posted it here.

Related

Having problems while trying to send two images to Backend via FormData

I'm trying to replicate this Postman Request on React Native. In this case, I'm taking two pictures with launchCamera and adding them to the DataForm, but it's not arriving succesfully on the backend.
This is the Postman Request I need to replicate
Not sure about it, but the problem seems to be happening on the second file
form1.append("file", {
name: response.assets[0].fileName, // Whatever your filename is
uri: response.assets[0].uri, // file:///data/user/0/com.cookingrn/cache/rn_image_picker_lib_temp_5f6898ee-a8d4-48c9-b265-142efb11ec3f.jpg
type: response.assets[0].type, // video/mp4 for videos..or image/png etc...
});
form1.append("file1", { //This is the other function where I take the second picture
name: response.assets[0].fileName, // Whatever your filename is
uri: response.assets[0].uri, // file:///data/user/0/com.cookingrn/cache/rn_image_picker_lib_temp_5f6898ee-a8d4-48c9-b265-142efb11ec3f.jpg
type: response.assets[0].type, // video/mp4 for videos..or image/png etc...
});
return fetch('https://seahorse-app-vm8c4.ondigitalocean.app/xxxxxx', {
method: 'POST',
headers: {
'Accept': '*/*',
'Content-Type': 'multipart/form-data;',
},
body: form1

Axios post spotify api request return 400

I am using spotify api for a project. Every request I made work fine except this one. I want to be able to create a new playlist. The scope was already checked, it's not the source of the problem. For this I made the following request
axios('https://api.spotify.com/v1/users/' + ID + '/playlists', {
method: 'POST',
headers: {
'Authorization' : 'Bearer ' + data.data.access_token,
"Content-Type" : "application/json"
},
data: {
name: Name,
Description: Description
}
})
when I tried it, I've got 400 Bad Request - The request could not be understood by the server due to malformed syntax. The message body will contain more information
Here's the link for the spotify api references
https://developer.spotify.com/documentation/web-api/reference/playlists/create-playlist/
assuming your ID is defined. You need to stringify your json.
Been a while since I used axios,
axios('https://api.spotify.com/v1/users/' + ID + '/playlists', {
method: 'POST',
headers: {
'Authorization' : 'Bearer ' + data.data.access_token,
'Content-Type': 'application/json'
},
data: JSON.stringify({
name: Name,
description: Description
})
})

Spotify WebPlayer API - Change Player Request

I've been working on a Spotify player using React, and so far I've been able to get the player to properly connect to the API and receive a device_id.
My next step is change the player to the newly "made" one, but I keep on receiving 400: Required field device_ids missing, even though I have it included in the PUT request:
const requestOptions = {
method: 'PUT',
headers: {
'Authorization' : 'Bearer ' + spotifyAccessToken
},
data: {
"device_ids": [device_id],
"play": 'true'
}
};
// Change player
fetch('https://api.spotify.com/v1/me/player', requestOptions)
Am I missing something/formatting it incorrectly? I've tried changing the data to body and I instead get a 400: Malformed JSON.
Thanks in advance!
I was able to get this working using the following format:
const requestOptions = {
method: 'PUT',
body: JSON.stringify({
device_ids: [southORadioDevId],
play: 'true'
}),
headers: {
Authorization: `Bearer ${spotifyAccessToken}`
},
};
// Change player
fetch('https://api.spotify.com/v1/me/player', requestOptions)

Cannot generate embed token using access token in power bi

I'm trying to be understand authorization mechanism in power bi API
I would embed a report in my web app.
I have done the steps as mentioned in docs
Actually I would get report embedded url then use power bi JS API to embed the report.
Getting access_token is successful
var options = {
'method': 'POST',
'url': `https://login.microsoftonline.com/${process.env.TENANT_ID}/oauth2/token`,
'headers': {
'Content-Type': 'multipart/form-data'
},
formData: {
'grant_type': process.env.GRANT_TYPE,
'client_id': process.env.CLIENT_ID,
'client_secret': process.env.CLIENT_SECRET,
'resource': "https://analysis.windows.net/powerbi/api",
'Scope': "https://analysis.windows.net/powerbi/api/.default"
}
};
Now I try to get embedded token for report in group
var data = { accessLevel: "View", datasetId: "5b11d62a-803e-46c9-83f3-*****" };
var config = {
method: 'post',
url: `https://api.powerbi.com/v1.0/myorg/groups/${process.env.GROUP_ID}/reports/${process.env.Report_ID}/GenerateToken`,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${JSON.parse(response).access_token}`
},
data: data
};
let embedtoken
try {
embedtoken = await axios(config)
}
catch (e) {
console.log(e)
}
context.res = {
// status: 200, /* Defaults to 200 */
body: JSON.parse(response).access_token
};
I get error 400 response
But When I generate an embed token for dashboard I get a valid token. But of course that's not working with get report API
My goal is to get report infos. For information I get get that using the access token but it's not safe
For POST API requests, data should be passed in string format. This can be done by using for example, JSON.stringify(data).
Refer below code snippet which should resolve the error.
var config = {
method: 'post',
url: `https://api.powerbi.com/v1.0/myorg/groups/${process.env.GROUP_ID}/reports/${process.env.Report_ID}/GenerateToken`,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${JSON.parse(response).access_token}`
},
data: JSON.stringify(data) };

Sending POST request weird issue

I'm quite new with ANGULAR and web development in general and I'm currently working on a web tool. Now I want this tool to send a POST request to a web service but Im encountering a weird bug. Now I have below code in my javascript:
var data_info = { test_id: 'TEST', model_id: 'TEST:TEST_ID' };
//data_info = JSON.stringify(data_info);
var request_json = {
method: 'POST',
url: url,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
data: data_info,
cache: false,
};
console.log(request_json);
$http(request_json).then(function successCallback(response) {
// response code here
}
Now this code currently doesn't pass the preflight request check and is always returning a 405. But if I change the line data: data_info in the request JSON into a new key let's say body: data_info it now successfully sends the request and I can confirm that the service is receiving it. I'm not sure what's the issue here and can't figure it out.
change your header to :
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
Please try

Resources