- Daniel Ferreira
- PowerBuilder
- Monday, 28 January 2019 11:02 PM UTC
Hi guru guys,
I have been successful calling a REST API using OLE Objets Msxml2.DOMDocument.6.0 and MSXML2.ServerXMLHTTP.6.0.
Now, I have an API with "Request Data" that I'm not being able to call from PB. Can any of you help?
This is the sample that works, it has no "Request Data":
ID = 97E0A5A956B64A74A4C241F6FFF19A82
api_token = d0f746328e2087a04a691879b803178d (yes, is for test purposes)
url = https://api.iugu.com/v1/subscriptions/ID/change_plan/teste
This is my code:
OleObject lole_Send
OleObject lole_SrvHTTP
String ls_status, ls_response_json
String ls_url = "https://api.iugu.com/v1/subscriptions/97E0A5A956B64A74A4C241F6FFF19A82/change_plan/teste?api_token=d0f746328e2087a04a691879b803178d"
lole_Send = Create OleObject
lole_SrvHTTP = Create OleObject
lole_Send.connectToNewObject("Msxml2.DOMDocument.6.0")
lole_SrvHTTP.connectToNewObject("MSXML2.ServerXMLHTTP.6.0")
lole_SrvHTTP.Open('POST', ls_url, False)
lole_SrvHTTP.SetRequestHeader("Content-Type", "application/json")
lole_SrvHTTP.Send(lole_Send)
ls_status = String(lole_SrvHTTP.Status)
ls_response_json = String(lole_SrvHTTP.ResponseText)
Now, this new API that I have to call has something called "REQUEST DATA", and I'm being able to send it. Can you advise? This is the metadata and JavaScript sample to it:
Metadata
METHOD: PUT
URL: https://api.iugu.com/v1/subscriptions/3EF8E2BB6DE44DD1A6D6DDF6492DB5C7?api_token=d0f746328e2087a04a691879b803178d
REQUEST HEADERS:
Accept: application/json
Content-Type: application/json
REQUEST DATA: (this is what I'm not being able to send)
{"plan_identifier":"teste","skip_charge":true}
Javascript sample:
var data = JSON.stringify({
"plan_identifier": "teste",
"skip_charge": "true"
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("PUT", "https://api.iugu.com/v1/subscriptions/3EF8E2BB6DE44DD1A6D6DDF6492DB5C7");
xhr.send(data);
Thanks, any help is appreciated.
Daniel
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.