I get it this way:
let options = { method: 'post', headers: {'content-type':'application/json','Access-Control-Allow-Credentials':true}, auth:{'username':process.env.PAYPALID,'password':process.env.PAYPALPASSWORD}, url: 'https://api.paypal.com/v1/oauth2/token', data: 'grant_type=client_credentials', } axios(options).then((response)=>{let paypaltoken=response.data.access_token axios.get('https://api.paypal.com/v1/payments/billing-agreements/'+agreementid+'/transactions?start_date=2018-01-01&end_date=2019-07-07', { headers: { 'Authorization':'Bearer '+paypaltoken, 'Content-Type':'application/json', } }) .then((transaction)=>{console.log(transaction.data)}) .catch(err => {console.error(err);console.log('err: '+JSON.stringify(err)); res.send (err) }) }) .catch(err => {console.error(err);console.log('err: '+JSON.stringify(err)); res.send (err) })
then, if you get only the transition.data file, you will get a series of transaction objects whose status == Completed only if the transaction went fine, that is, it was not canceled, so just check the last one for plan control purposes, When status == Canceled you you know that the agreement is no longer active.
Another way to do this if you receive monthly payments is to set the first date for 2 months from "now ()" and the second date to "now ()". If you do not receive transactions, then the status may not be active, but check again: there is a random chance that there might be some problems with a credit card. In this case, I believe that status could be == delayed or something else, but I did not have the opportunity to check it, so I donβt know. The idea arose from this question and the second relative answer, which deserves my thanks as much as Cyril ALFARO.
Please note that depending on your case, you may need to add 'Access-Control-Allow-Credentials':true to the headers instead of other withCredentials: true or similar in the request.
Amdp
source share