Currently I am working on an app for Active Collab with ionic (AngularJS). When I tracked some time I want to post this time, so that I'll have this time in Active Collab. But when I tried to do that, I got an 500 Internal Server Error. This is my Code (I used the data from the Active Collab API Documentation, to test):
var postData = {
"value": 1.5,
"user_id": 1,
"job_type_id": 1,
"record_date": "2014-05-14",
"billable_status": 0
};
$http.post(baseUrl+'/projects/' + projectId +'/time-records/', postData, { headers: { 'Content-Type': 'application/json' }}).then(function(res){ ... }
The post request work for getting the token (issue-token). So I have no idea what the problem is. I hope anyone can help me?
To make the token-post working I had to add some lines to api.php. Wouldn't this be good to be there per default?
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
// return only the headers and not the content
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
header('Access-Control-Allow-Headers: X-Requested-With');
}
exit;
}
Thanks in advance!
I am currently running Active Collab locally. So baseUrl is: http://my-ip-address/mypath-to-ac/api/v5/projects/56/time-records/ . I do have an authInterceptor, so token should be appended. I also tried to send it within the post-request, but got same error.
Now I debugged it a little more and it says that some fields are null. But I definitely filled those fields and sent them.
This is the logged Data, that I'll send with the request:
{"value":"1.5","user_id":10,"job_type_id":"0","record_date":1467965415.184,"billable_status":0}
And this is the error, I'll get:
debugged error as screenshot
Related
I am working on an application in php where I have to integrate PayPal Smart Buttons to my application. Everything is working fine in sandbox mode. But when I turn it to Live or Production Environment. It gives JSON error.
PayPal Smart Buttons returns me JSON error
This answer helped me alot while setting up my environment for sandbox and everything else, this is working really fine. but only for sandbox mode!
I checked with account on paypal, the transactions are created there, but no response is being sent to server for further processing. It indicates the API is setup successfully and keys are good. But only issue is I m unable to capture response and send it back to server here is my code
create-paypal-transaction.php
public static function createOrder($debug=false)
{
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = self::buildRequestBody();
// 3. Call PayPal to set up a transaction
$client = PayPalClient::client();
$response = $client->execute($request);
// 4. Return a successful response to the client.
$json_obj= array('id'=>$response->result->id);
$jsonstring = json_encode($json_obj);
echo $jsonstring;
}
on client side
createOrder: function() {
return fetch('payments/create-paypal-transaction.php', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify($('#form_add').serializeObject())
}).then(function(res) {
console.log(res);
return res.json();
}).then(function(data) {
console.log(data);
return data.id;
});
I used console.log() for debugging server response but it is always
{
...
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
...
}
also the console shows below errors
create_order_error
click_initiate_payment_reject
Uncaught SyntaxError: Unexpected token < in JSON at position 0
ANY HELP WOULD BE APPRECIATED :)
Im getting the same issue, i've read that you need to redirect them to the approval url like such
public static function createOrder($debug=false)
{
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = self::buildRequestBody();
// 3. Call PayPal to set up a transaction
$client = PayPalClient::client();
$response = $client->execute($request);
$res_links = $response->result->links;
$approve_index = array_search('approve',array_column($res_links,'rel'));
redirect($res_links[$approve_index]->href);
// 4. Return a successful response to the client.
$json_obj= array('id'=>$response->result->id);
$jsonstring = json_encode($json_obj);
echo $jsonstring;
}
This ends up giving a cors error and when bypassing the cors checking in chrome(which is terrible) it simply closes the checkout popup and the response for the approval url is the html for the page.
In the network tab in your dev console, check the response for the create-paypal-transaction.php file. It'l give you the actual error the json > error is unrelated. You can also visit the file directly from your browser and see what errors you get there.
You can message me on discord if youd like im also working on getting this working. REDRUM#9269
I'm trying to update one of my subscriber's status using mailchimp API 3.0, Meteor and javascript.
Here is my js code I'm using:
request({
uri,
list_id,
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'apikey (my api key)'
},
json,
}, function(err, res, body) {
if (err) {
return console.log("err:", err);
}
console.log("connection succeed");
console.log("res: ", res.body);
console.log("body: ", body);
});
with
uri = "https://us15.api.mailchimp.com/3.0/lists/" + (id of my list) + "/members/" + (md5 of my user mail);
and
json = {
"email_address": (user mail as a string),
"status": "unsubscribed"
};
But I always have the same output:
I20181204-18:42:12.714(8)? title: 'Member Exists',
I20181204-18:42:12.714(8)? status: 400, I20181204-18:42:12.714(8)? detail: '(user mail adress) is already a list member. Use PUT
to insert or update list members.'
But I am using PUT already... The request works with POST if it's the first time I add the user. But now I can't update my user status...
Is something wrong with my request or with the way I use the API? Thanks in advance.
EDIT 1 -> trying with GET doesn't work. The request itself is correct but it has no effect on my subscriber's status. So I still need to make PUT work.
After looking at the official doc in the "Edit" tab, I found the answer!
The json required another mandatory parameter and should look like this:
json = {
"email_address": (user mail as a string),
"status_if_new": "unsubscribed",
"status": "unsubscribed"
};
I know that this is an older question but I just wanted to add something in the event that it helps someone.
I was having a similar issue intermittently with most of my PUT requests working as expected and some not.
It took me a while but eventually I figured out that some of my email addresses had spaces at the end.
This error would result.
Trimming the addresses before doing anything resolved my issue.
I'm trying to access the response of my POST request in Postman via Post Request Script.
I added this 2 lines, under Pre-request Script
let response = pm.response.json();
console.log('JSON Response: ',response );
Then, I opened up my Postman console, before hit Send to make my POST request
I kept getting
There was an error in evaluating the Pre-request Script: TypeError: Cannot read property 'json' of undefined
Do I need to enable anything on Postman?
Pre-request scripts are ran before the request is sent. You do not have a response yet.
Try putting your script under the Tests tab, which is ran after a response is received.
In my case, there was a script that was screwing up my request. If you get the postman collection from someone else, check this and try to fix it. (in my case I don't need it so I deleted it)
You can try setting an environment variable, get it and parse it, I was created a POST requests to make a login and get a token to each request.
const echoPostRequest = {
url: pm.environment.get("url_login"),
method: 'POST',
header: 'Content-Type: application/json',
body: {
mode: 'raw',
raw: JSON.stringify({ email: pm.environment.get("user"),password: pm.environment.get("password") })
}
};
pm.sendRequest(echoPostRequest, function (err, res) {
console.log(err ? err : res.json());
pm.environment.set("login_response", res.json());
pm.environment.set("bearer_token", pm.environment.get("login_response").bearer_token);
});
was helping a friend and he had tried to make an adjustment to all requests in the collection.
I found in the documentation, how to remove
https://learning.postman.com/docs/writing-scripts/pre-request-scripts/
Please Make Sure That You Cleared Text Area Of PRE-REQUEST & TESTS TAB
By Clearing Text I Solved This Issue
Check if you SSL was turn off. If isn't, turn off.
Settings >> General >> SSL Certificate Verification
I want to fetch some data from a server via axios in my react project. When i put the url on browser and hit enter browser ask me username and password and after that, i can see the json data. But i dont know how to set the password and username in axios header in a get method. I have searched it in many forums and pages,especially this link didin't help me: Sending axios get request with authorization header . So finally i tried (many things before this, but i was more confused):
componentDidMount() {
axios.get('http://my_url/api/stb', {auth: {
username: 'usrnm',
password: 'pswrd'
}})
.then(function(response) {
console.log(response.data);
console.log(response.headers['Authorization']);
}).catch(err => console.log(err));
}
And i can not get anything. I get this error in console:
Error: Network Error
Stack trace:
createError#http://localhost:3000/static/js/bundle.js:2195:15
handleError#http://localhost:3000/static/js/bundle.js:1724:14
Actually, the api documentation mentioned that with these words:
If there is no header or not correct data - server's answer will
contain HTTP status 401 Unauthorized and message:
< {"status":"ERROR","results":"","error":"401 Unauthorized request"}
For successful authentification is sufficient to add in every request
header to the API:
Authorization: Basic <base64encode("login":"password")>
The weird thing is, when i use postman, the response send me a "401 unauthorized" response below the body section. But i can not see any 401 errors in browser's console.
Ok i found the solution. As i mentioned in the comments that i wrote for my question, there was a cors problem also. And i figured out that cors problem was appearing because of that i can not authorize correctly. So cors is a nature result of my question. Whatever.. I want to share my solution and i hope it helps another people because i couldent find a clear authorization example with react and axios.
I installed base-64 library via npm and:
componentDidMount() {
const tok = 'my_username:my_password';
const hash = Base64.encode(tok);
const Basic = 'Basic ' + hash;
axios.get('http://my_url/api/stb', {headers : { 'Authorization' : Basic }})
.then(function(response) {
console.log(response.data);
console.log(response.headers['Authorization']);
}).catch(err => console.log(err));
}
And dont forget to get Authorization in single quotes and dont struggle for hours like me :)
I'm using this instruction https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/advanced-integration/ to set up paypal. The only different is that I need to send data to CREATE_PAYMENT_URL endpoint, so I transfer it as second parameter
paypal.request.post(
CREATE_PAYMENT_URL,
JSON.stringify([{"name": "test", "price": 10}]),
{ headers: { 'Content-Type': 'application/json' } }
)
after that I'm getting 400 error
{"success":false,"errors":{"statuscode":400,"message":"Invalid json message received"}}
Backend doesn't matter, cause it's never reached. Also I'm almost sure it worked fine few days ago
Any ideas?
Fiddler screen
Try setting the second param to null, and send an options object as the third param with an object named json in the third with a plain JS object inside.
paypal.request.post(PAYMENT_URL, null, {
json : {
name:'test',
price:10
}
})
It's not in the documentation, I was having similar issues but dug around in the source code to get it to work.