Reading data in an inner array with pljson - pljson

Sample JSON:
{"TestResults": [{
"Messages": ["PASS: Status date 7/1/2002, ID"],
"Status": "Pass",
"Name": "IFTA License"
},
{
"Messages": ["Carrier compliant"],
"Status": "Pass",
"Name": "MCOLS carrier compliance check"
},
{
"Messages": ["No"],
"Status": "Pass",
"Name": "IFTA Revoked"
},
{
"Messages": ["PASS=> Not under Federal Out Of Service order"],
"Status": "Pass",
"Name": "Federal Out of Service Status"
},
{
"Messages": ["PASS => Carrier status code 100: Active ID"],
"Status": "Pass",
"Name": "IRP Status"
},
{
"Messages": ["PASS => Status Code 1: Active"],
"Status": "Pass",
"Name": "IFTA Status"
},
{
"Messages": ["PASS => UCR fee paid for 2017",
"PASS => UCR fee paid for 2016"],
"Status": "Pass",
"Name": "UCR Fee Status"
},
{
"Messages": ["PASS => MCMIS Status = A: Active"],
"Status": "Pass",
"Name": "USDOT Status"
},
{
"Messages": ["PASS=> Not under Federal Out Of Service order"],
"Status": "Pass",
"Name": "PRISM Target Status"
},
{
"Messages": ["PASS => ISS Score: 42 No Inspection Warranted"],
"Status": "Pass",
"Name": "ISS2 Score"
},
{
"Messages": ["PASS => MCS-150 Up to Date: Last Update 4/28/2016"],
"Status": "Pass",
"Name": "MCS-150 Status"
},
{
"Messages": ["PASS => Carrier is authorized"],
"Status": "Pass",
"Name": "Operating Authority Status"
}]
}
Code utilizing pljson:
DECLARE
l_http_req UTL_HTTP.REQ;
l_http_resp UTL_HTTP.RESP;
l_response CLOB;
l_buffer VARCHAR2(4000);
l_response_json common.json;
l_testresults_list common.json_list;
l_messages_list common.json_list;
BEGIN
utl_http.set_wallet('file:/home/oracle/wallet/blah',NULL);
l_http_req := utl_http.begin_request('https://some_url', 'GET');
utl_http.set_header(l_http_req, 'Content-Type', 'application/json');
utl_http.set_authentication(l_http_req, 'user', 'password');
BEGIN
dbms_lob.createtemporary(l_response, TRUE);
dbms_lob.open(l_response, dbms_lob.lob_readwrite);
l_http_resp := utl_http.get_response(l_http_req);
LOOP
utl_http.read_text(l_http_resp, l_buffer, 2000);
dbms_lob.writeappend(l_response, LENGTH(l_buffer), l_buffer);
END LOOP;
EXCEPTION
WHEN utl_http.end_of_body THEN
NULL;
WHEN OTHERS THEN
RAISE;
END;
dbms_lob.close(l_response);
utl_http.end_response(l_http_resp);
-- Convert CLOB content to JSON object.
BEGIN
l_response_json := common.json(l_response);
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
BEGIN
l_testresults_list := json_ext.get_json_list(l_response_json, 'TestResults');
FOR i IN 1..l_testresults_list.COUNT LOOP
dbms_output.put_line('name: '||common.json_ext.get_string(common.json(l_testresults_list.GET(i)), 'Name'));
dbms_output.put_line('status: '||common.json_ext.get_string(common.json(l_testresults_list.GET(i)), 'Status'));
l_messages_list := json_ext.get_json_list(common.json(l_testresults_list.GET(i)), 'Messages');
FOR j IN 1..l_messages_list.COUNT LOOP
dbms_output.put_line('messages: '||common.json_ext.get_string(common.json(l_messages_list.GET(j)), 'Messages'));
dbms_output.put_line('count : '||j);
END LOOP;
END LOOP;
END;
EXCEPTION
WHEN OTHERS THEN
utl_http.end_response(l_http_resp);
RAISE;
END;
I'm able to extract the name and status values from this JSON, but when this line of code is executed to extract the messages:
dbms_output.put_line('messages: '||common.json_ext.get_string(common.json(l_messages_list.GET(j)), 'Messages'));
I receive an ORA-30625: method dispatch on NULL SELF argument is disallowed
Has anyone been able to successfully read values from an inner array with pljson?

Since you are working with the array, you should be able to simply:
dbms_output.put_line( l_messages_list.get(j).to_char() );

Related

Cosmos Nested JSON Query

This is the fist time that I work with CosmosDB and I am trying to create a Query to get some details about this JSON:
{
"Status": "Uploaded",
"ProvidedOn": "2022-04-04T18:34:57.4160484Z",
"DocumentTaxonomy": {
"JurisdictionalCountriesOfService": [
{
"Id": 5,
"Name": "United States"
}
],
"WorkProduct": {
"Id": 762,
"Name": "Other reports and documents",
"Type": "Info item"
}
},
"id": "3a92c052-bc23-4b8a-acbf-54044785968a",
"Meta": {
"VersionId": "3",
"LastUpdated": "0001-01-01T00:00:00",
"Source": null,
"Security": null,
"Tag": null,
"Id": null,
"Extension": null,
"ModifierExtension": null
},
}
Basicaly I need to get something like
SELECT id,Status,ProvidedOn, WorkProductName, WorkProductType,MetaVersionId FROM JSONFILE
In this image I am highlighting the columnsthat my query needs
NOTE: since I need to query different CosmoDB, not all of them have the DocumentTaxonomy section so the plan is when they doesn't exists return like a null or blank value
As per your question, the code should return the DocumentTaxonomy section values if they exist in the JSON otherwise It should return null or blank values.
This code may work for you:
SELECT c.id, c.ProvidedOn, c.Status,c.Meta.VersionId as versionId,
IS_DEFINED(c.DocumentTaxonomy.WorkProduct.Type) = true ? c.DocumentTaxonomy.WorkProduct.Type
: IS_DEFINED(c.DocumentTaxonomy.WorkProduct.Type) = false ? null
: "some default value"
as TypeDoc,
IS_DEFINED(c.DocumentTaxonomy.WorkProduct.Name) = true ? c.DocumentTaxonomy.WorkProduct.Name
: IS_DEFINED(c.DocumentTaxonomy.WorkProduct.Name) = false ? null
: "some default value"
as NameDoc
FROM c
The Output it gave when DocumentTaxonomy section exists is:
[
{
"id": "3a92c052-bc23-4b8a-acbf-54044785968a",
"ProvidedOn": "2022-04-04T18:34:57.4160484Z",
"Status": "Uploaded",
"versionId": "3",
"TypeDoc": "Info item",
"NameDoc": "Other reports and documents"
}
]
The Output when DocumentTaxonomy section not exists :
[
{
"id": "3a92c052-bc23-4b8a-acbf-54044785968a",
"ProvidedOn": "2022-04-04T18:34:57.4160484Z",
"Status": "Uploaded",
"versionId": "3",
"TypeDoc": null,
"NameDoc": null
}
]
Please check the screenshot of the output for your reference:

Stripe: getting "You cannot request any capability other than `transfers`" when only requesting transfers

I'm setting up a test connect account through Stripe, but for some reason during the onboarding I get:
You cannot request any capability other than transfers for accounts that are under the recipient service agreement.
even though I set the capabilities only to transfers.requested: true.
Full details:
1. I created a connect account
Request:
POST https://api.stripe.com/v1/accounts
x-www-form-urlencoded body:
tos_acceptance[service_agreement]: recipient
capabilities[transfers][requested]: true
country: AT
type: express
Response:
{
"id": "acct_1IEKs6Q5kVIyiDKZ",
"object": "account",
"business_profile": {
"mcc": null,
"name": null,
"product_description": null,
"support_address": null,
"support_email": null,
"support_phone": null,
"support_url": null,
"url": null
},
"business_type": null,
"capabilities": {
"transfers": "inactive"
},
"charges_enabled": false,
"country": "AT",
"created": 1611780255,
"default_currency": "eur",
"details_submitted": false,
"email": null,
"external_accounts": {
"object": "list",
"data": [],
"has_more": false,
"total_count": 0,
"url": "/v1/accounts/acct_1IEKs6Q5kVIyiDKZ/external_accounts"
},
"login_links": {
"object": "list",
"total_count": 0,
"has_more": false,
"url": "/v1/accounts/acct_1IEKs6Q5kVIyiDKZ/login_links",
"data": []
},
"metadata": {},
"payouts_enabled": false,
"requirements": {
"current_deadline": null,
"currently_due": [
"business_type",
"external_account",
"tos_acceptance.date",
"tos_acceptance.ip"
],
"disabled_reason": "requirements.past_due",
"errors": [],
"eventually_due": [
"business_type",
"external_account",
"tos_acceptance.date",
"tos_acceptance.ip"
],
"past_due": [
"business_type",
"external_account",
"tos_acceptance.date",
"tos_acceptance.ip"
],
"pending_verification": []
},
"settings": {
"bacs_debit_payments": {},
"branding": {
"icon": null,
"logo": null,
"primary_color": null,
"secondary_color": null
},
"card_payments": {
"decline_on": {
"avs_failure": false,
"cvc_failure": false
},
"statement_descriptor_prefix": null
},
"dashboard": {
"display_name": "Some business LLC",
"timezone": "Etc/UTC"
},
"payments": {
"statement_descriptor": null,
"statement_descriptor_kana": null,
"statement_descriptor_kanji": null
},
"payouts": {
"debit_negative_balances": false,
"schedule": {
"delay_days": 7,
"interval": "daily"
},
"statement_descriptor": null
},
"sepa_debit_payments": {}
},
"tos_acceptance": {
"date": null,
"ip": null,
"service_agreement": "recipient",
"user_agent": null
},
"type": "express"
}
2. Got the onboarding link:
Request:
POST https://api.stripe.com/v1/accounts
x-www-form-urlencoded body:
account: acct_1IEKs6Q5kVIyiDKZ
refresh_url: https://example.com/reauth
return_url: https://example.com/return
type: account_onboarding
Response:
{
"object": "account_link",
"created": 1611780861,
"expires_at": 1611781161,
"url": "https://connect.stripe.com/express/onboarding/<some string>"
}
3. Went to the onboarding link
I got an error after pressing Next on the Tell us about your business section.
You cannot request any capability other than transfers for accounts that are under the recipient service agreement. For more information on recipient service agreements, see https://stripe.com/docs/connect/service-agreement-types#recipient.
Why does stripe think I'm requesting capabilities other than transfers?
Stripe got back to me:
The error is a bit cryptic but it is likely due to the way you configured Connect Onboarding in your settings in the Dashboard. This error happens because we try to request the card_payments capability for this account but it's not supported because you use the recipient agreement type. The reason we ask for that capability comes from the fact that you configured Connect to require that capability for European accounts. You can change this default behaviour in your dashboard settings in Test mode here: https://dashboard.stripe.com/test/settings/applications/express (and you would do the same for Live mode). With your flow you want only Transfers as a capability.
The suggestion worked:
Incorrect Settings:
Correct Settings:
It's strange because I used to be able to create accounts from these requests. So the settings must have changed at some point. But to my knowledge I never went and changed them.

Calendar API Event Attendees Response Status always changes to "Needs Action"

I am doing callout from salesforce to google calendar api to upsert a google event. when i make the request, it always changes the attendee status to "NeedsAction", so when I sent request to google, attendee status was "Accepted" but in response i got "NeedsAction". Why google always changes the attendee response. Please help if anyone knows. Thanks
Request Body :
{
"kind" : "calendar#event",
"summary" : "nice 13 val",
"description" : "this is new",
"location" : "3 value friday",
"start" : {
"dateTime" : "2020-08-13T12:30:00+05:00"
},
"end" : {
"dateTime" : "2020-08-13T13:30:00+05:00"
},
"attendees" : [ {
"email" : "mohit.kumar#test.in",
"organizer" : true,
"responseStatus" : "accepted"
}, {
"email" : "test#gmail.com",
"responseStatus" : "accepted"
} ]
}
Callout :
Http http = new Http();
HttpRequest httpReq = new HttpRequest();
httpReq.setEndpoint('https://www.googleapis.com/calendar/v3/calendars/mohit.kumar#test.in/events/'+objEvent.Google_Event_Id__c);
httpReq.setTimeout(30000);
httpReq.setHeader('Content-Type', 'application/json');
httpReq.setMethod('POST');
httpReq.setHeader('X-HTTP-Method-Override','PATCH');
httpReq.setHeader('Authorization', 'Bearer ' + accessToken);
String reqBody = createEventBody(objEvent, googleSettingInfo);
if (String.isNotBlank(reqBody)) {
httpReq.setBody(reqBody);
}
if (httpReq.getBody() != null && httpReq.getBody() != '') {
HttpResponse httpRes = http.send(httpReq);
System.debug('code: ' + httpRes.getStatusCode());
if (httpRes.getStatusCode() == 200) {
System.debug('response: ' + httpRes);
System.debug('create event response body: ' + httpRes.getBody());
}
}
getting attendees response always as "needs Action" while this should be "accepted" for "test#gmail.com"
{
"created": "2020-08-11T18:51:41.000Z",
"updated": "2020-08-28T06:48:49.972Z",
"summary": "nice 13 val",
"description": "this is new",
"location": "3 value friday",
"creator": {
"email": "mohit.kumar#test.in",
"self": true
},
"organizer": {
"email": "mohit.kumar#test.in",
"self": true
},
"start": {
"dateTime": "2020-08-13T14:00:00+05:30"
},
"end": {
"dateTime": "2020-08-13T15:00:00+05:30"
},
"sequence": 16,
"attendees": [
{
"email": "test#gmail.com",
"responseStatus": "needsAction"
},
{
"email": "mohit.kumar#test.in",
"organizer": true,
"self": true,
"responseStatus": "accepted"
}
],
Proposed modification:
What about modifying the createEventBody function in order to create a simple JSON object that will only contain the attendees information with the updated statuses.
This will leverage correctly the PATCH semantics and helps a lot on improving readability.
I tested it myself and your generated JSON object returns an error on the start property. Removing that will help you solve that error too. Finally I tested that passing the attendees property to the PATCH method will work as intended.
You can try using the "Try this API" functionality before actually update your code.
Reference:
Events patch

Why I'm not geting token in res in braintree?

I'm using braintree for payment and I have done this.
gateway.customer.create({
firstName: "Sachin",
lastName: "Shah",
company: "Qwerty",
email: "Qwerty#example.com",
phone: "114.555.1234",
fax: "614.555.1234",
website: "www.example.com",
}, function (err, result) {
if (err) {
res.send({code:0, status:'Error', message:err});
}else{
res.send({code:1, status:'Success', data: result});
}
});
I followed it's official doc and they show that when req is success I'll get token but I'm gtting result.customer.paymentMethods[]
Response
{
"code": 1,
"status": "Success",
"data": {
"customer": {
"id": "569549779",
"merchantId": "XXXXXXXXXXXXXXXXX",
"firstName": "Sachin",
"lastName": "Shah",
"company": "Qwerty",
"email": "Qwerty#example.com",
"phone": "114.555.1234",
"fax": "614.555.1234",
"website": "www.example.com",
"createdAt": "2019-10-10T05:13:42Z",
"updatedAt": "2019-10-10T05:13:42Z",
"customFields": "",
"globalId": "XXXXXXXXXXXXXXXXX",
"creditCards": [],
"addresses": [],
"paymentMethods": []
},
"success": true
}
}
Expected Output
I need to get paymentMethodToken for further API calls.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
You're currently creating a customer without a payment method. You'll need to create the customer with a payment method to retrieve a paymentMethodToken.

Why is this pact-jvm provider test failing?

We’ve got a provider test that is only failing on Jenkins, which is preventing me from debugging.
Here are some relevant logs from Jenkins:
Error Message
0 - $.body.2 -> Expected name='FXUHHqWrZZcodhHBmeLf' but was missing
0) a request to get all clients returns a response which has a matching body
$.body.2 -> Expected name='FXUHHqWrZZcodhHBmeLf' but was missing
Diff:
(some ommissions…)
#10
],
- "id": "c53927c3-0d1c-48a8-8f0a-7560be89daa5",
- "name": "FXUHHqWrZZcodhHBmeLf",
+ "id": "9daaad0a-8a2d-4e73-a963-fa1625cec110",
+ "name": "name",
+ "privileges": [
+ "CHECK_TOKEN",
+ "MANAGE_CLIENT",
+ "MANAGE_IDP",
+ "MANAGE_USER"
+ ],
"redirectUris": [
And the interaction looks like this in the pact file:
{
"description": "a request to get all clients",
"request": {
"method": "GET",
"path": "/some/url/client"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json; charset=UTF-8"
},
"body": [
{
"accessTokenValiditySeconds": 42721462,
"allowedScopes": [
"JnTfAlnHKVSDzoWnUqZv"
],
"autoApprove": true,
"grantTypes": [
"VfWudsTQINERQCnVKvoK"
],
"id": "c53927c3-0d1c-48a8-8f0a-7560be89daa5",
"name": "FXUHHqWrZZcodhHBmeLf",
"redirectUris": [
"vWxSTjgJQvwUtwphDGcn"
],
"refreshTokenValiditySeconds": 12393550,
"secretRequired": true
}
],
"matchingRules": {
"$.body[*].allowedScopes[*]": {
"match": "type"
},
"$.body[*].redirectUris[*]": {
"match": "type"
},
"$.body[*].grantTypes[*]": {
"match": "type"
},
"$.body[*].redirectUris": {
"min": 0,
"match": "type"
},
"$.body[*].autoApprove": {
"match": "type"
},
"$.body": {
"min": 1,
"match": "type"
},
"$.body[*].id": {
"regex": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
},
"$.body[*].accessTokenValiditySeconds": {
"match": "integer"
},
"$.body[*].secretRequired": {
"match": "type"
},
"$.body[*].refreshTokenValiditySeconds": {
"match": "integer"
},
"$.body[*].name": {
"match": "type"
},
"$.body[*].allowedScopes": {
"min": 0,
"match": "type"
},
"$.body[*].grantTypes": {
"min": 0,
"match": "type"
}
}
},
"providerState": "the 'zero' client exists"
},
I'm under the impression that the name should be matching on type instead of the exact value, and it appears that there is a "name" field in the diff.
Why is this test failing?
edit:
This is the code to produce the pact fragment:
builder
.given("the 'zero' client exists")
.uponReceiving("a request to get all clients")
.path("/some/url/client")
.method("GET")
.willRespondWith()
.status(200)
.body(PactDslJsonArray
.arrayMinLike(1)
.uuid("id")
.booleanType("secretRequired")
.eachLike("allowedScopes", stringType())
.eachLike("grantTypes", stringType())
.eachLike("redirectUris", stringType())
.integerType("accessTokenValiditySeconds")
.integerType("refreshTokenValiditySeconds")
.booleanType("autoApprove")
.stringType("name")
.closeObject())
.toFragment();
The important bit of information in the logs is the 'but was missing' bit. It seems to indicate that the third item in the array (matched by '$.body.2') was missing the name attribute.
Can you double check the full response, and if there is a name attribute in the third item, then could you kindly raise an issue at https://github.com/DiUS/pact-jvm.

Resources