Swagger UI Access-Control-Allow-Origin Error - php

I have my Laravel PHP application where API is hosted on https://site.example.com and I have Swagger UP API Doc hosted on https://api.example.com. when I try API on Swagger API it gives Access-Control-Allow-Origin Error error. Following is my swagger.json
{
"openapi": "3.0.0",
"info": {
"title": "Seller-Hub",
"description": "",
"license": {
"name": "-"
},
"version": "1.1.0"
},
"servers": [
{
"url": "https://site.example.com/public/api/v1",
"description": "Dev server"
},
],
"paths": {
"/seller": {
"get": {
"tags": [
"Seller"
],
"summary": "Returns Seller Data",
"description": "Returns a map of Seller Data",
"operationId": "seller",
"parameters": [
],
"responses": {
"200": {
"description": "successful operation",
"headers":{
"Access-Control-Allow-Origin":{
"schema":{
"type": "string"
}
},
"Access-Control-Allow-Methods":{
"schema":{
"type": "string"
}
},
"Access-Control-Allow-Headers":{
"schema":{
"type": "string"
}
},
},
"content": {
"application/json": {
"schema": {
}
}
}
},
},
"security": [
{
"ApiSign": []
}
]
}
},
"components": {
"securitySchemes": {
"ApiSign": {
"type": "apiKey",
"in": "header",
"name": "authorization"
}
}
},
}
I am not getting where to pass Access control as headers. I have tried every possible way but no success. any help would be great. Thanks

Related

Extract element from nested JSON

There is json response:
{
"id": "1234567890123456789",
"creation_date": 12345678,
"event": "WAITING_PAYMENT",
"version": "2.0.0",
"data": {
"product": {
"id": 213344,
"name": "Product Name",
"has_co_production": false
},
"affiliates": [
{
"name": "Affiliate name"
}
],
"buyer": {
"email": "buyer#email.com"
},
"producer": {
"name": "Producer Name"
},
"commissions": [
{
"value": 0.65,
"source": "MARKETPLACE"
},
{
"value": 3.10,
"source": "PRODUCER"
}
],
"purchase": {
"approved_date": 1231241434453,
"full_price": {
"value": 134.0
},
"original_offer_price": {
"currency_value": "EUR"
"value": 100.78,
},
"price": {
"value": 150.6
},
"order_date": "123243546",
"status": "STARTED",
"transaction": "HP02316330308193",
"payment": {
"billet_barcode": "03399.33335 33823.303087 198801027 2 876300015000",
"billet_url": "https://billet-link.com/bHP023163303193",
}
},
"subscription": {
"status": "ACTIVE",
"plan": {
"name": "plan name"
},
"subscriber": {
"code": "12133421"
}
}
}
}
My question is how to extract data["buyer"]["email"] in PHP ?
I only need to extract the email information from the buyer table inside the data table.
First, you need to decode the json to a PHP array (or an object), then you can access the requested information from the decoded data.
$data = json_decode('the json string most place here', true);
$email = $data['buyer']['email'];
Place your json string in the first argument of json_decode() function.

Wordpress 401 error: rest_forbidden. Sorry, you are not allowed to make proxied oEmbed requests

I'm getting 401 error on the following URL call on my Wordpress hosted on Windows IIS server:
https://example.com/wp-json/oembed/1.0/proxy?url=https://example.com/wp-content/uploads/img.jpg
{
"code": "rest_forbidden",
"message": "Sorry, you are not allowed to make proxied oEmbed requests.",
"data": {
"status": 401
}
}
The above URL is called by the Elementor gallery widget when I want to set an external image for it.
Although, the following URL is working on my Wordpress site:
https://example.com/wp-json/oembed/1.0?url=https://example.com/wp-content/uploads/img.jpg
{
"namespace": "oembed\/1.0",
"routes": {
"\/oembed\/1.0": {
"namespace": "oembed\/1.0",
"methods": ["GET"],
"endpoints": [{
"methods": ["GET"],
"args": {
"namespace": {
"default": "oembed\/1.0",
"required": false
},
"context": {
"default": "view",
"required": false
}
}
}
],
"_links": {
"self": [{
"href": "https:\/\/example.com\/wp-json\/oembed\/1.0"
}
]
}
},
"\/oembed\/1.0\/embed": {
"namespace": "oembed\/1.0",
"methods": ["GET"],
"endpoints": [{
"methods": ["GET"],
"args": {
"url": {
"description": "The URL of the resource for which to fetch oEmbed data.",
"type": "string",
"format": "uri",
"required": true
},
"format": {
"default": "json",
"required": false
},
"maxwidth": {
"default": 600,
"required": false
}
}
}
],
"_links": {
"self": [{
"href": "https:\/\/example.com\/wp-json\/oembed\/1.0\/embed"
}
]
}
},
"\/oembed\/1.0\/proxy": {
"namespace": "oembed\/1.0",
"methods": ["GET"],
"endpoints": [{
"methods": ["GET"],
"args": {
"url": {
"description": "The URL of the resource for which to fetch oEmbed data.",
"type": "string",
"format": "uri",
"required": true
},
"format": {
"description": "The oEmbed format to use.",
"type": "string",
"default": "json",
"enum": ["json", "xml"],
"required": false
},
"maxwidth": {
"description": "The maximum width of the embed frame in pixels.",
"type": "integer",
"default": 600,
"required": false
},
"maxheight": {
"description": "The maximum height of the embed frame in pixels.",
"type": "integer",
"required": false
},
"discover": {
"description": "Whether to perform an oEmbed discovery request for unsanctioned providers.",
"type": "boolean",
"default": true,
"required": false
}
}
}
],
"_links": {
"self": [{
"href": "https:\/\/example.com\/wp-json\/oembed\/1.0\/proxy"
}
]
}
}
},
"_links": {
"up": [{
"href": "https:\/\/example.com\/wp-json\/"
}
]
}
}
PHP: 7.4.16
Wordpress: 5.6.2
Windows Server: 2019

Google Analytics API in inserting goals using PHP

I need help regarding the returned error after initiating request:
Here's the request body:
{
"name": "Test Leads",
"id": "2",
"type": "Event",
"active": true,
"eventDetails": {
"eventConditions": [
{
"type": "Category",
"comparisonType": "EQUAL",
"expression": "Leads"
},
{
"type": "ACTION",
"comparisonType": "EQUAL",
"expression": "Create"
}
],
"useEventValue": true
}
}
Error:
{"error":{
"errors":[
{"domain":"global","reason":"backendError","message":"Backend Error"}
],
"code":500,
"message":"Backend Error"
}
}
Expected Goal Details when successfully posted:
https://www.screencast.com/t/5QOJ28Tnk
Can someone check the code and see what's wrong or missing?
Thanks.
"name": "Test Leads",
"kind": "analytics#goal",
"id": "2",
"type": "Event",
"active": true,
"eventDetails": {
"eventConditions": [
{
"type": "CATEGORY",
"matchType": "EXACT",
"expression": "Leads"
},
{
"type": "ACTION",
"matchType": "EXACT",
"expression": "Create"
}
],
"useEventValue": true
}
}```

handaling JSON Data in php [duplicate]

This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
Closed 6 years ago.
I got a json data in return in my php script and this json data is stored in my variable. Now i would like to check the "price" for name "express" in php. Please guide me the way to extract the data in php.
$serviceTypesJSON = json_decode($rawBody, true);
{
"services": {
"service": [
{
"code": "INT_PARCEL_COR_OWN_PACKAGING",
"name": "Courier",
"price": "85.13",
"max_extra_cover": 5000,
"options": {
"option": [
{
"code": "INT_TRACKING",
"name": "Tracking"
},
{
"code": "INT_SMS_TRACK_ADVICE",
"name": "SMS track advice"
},
{
"code": "INT_EXTRA_COVER",
"name": "Extra Cover"
}
]
}
},
{
"code": "INT_PARCEL_EXP_OWN_PACKAGING",
"name": "Express",
"price": "40.13",
"max_extra_cover": 5000,
"options": {
"option": [
{
"code": "INT_TRACKING",
"name": "Tracking"
},
{
"code": "INT_SIGNATURE_ON_DELIVERY",
"name": "Signature on delivery"
},
{
"code": "INT_SMS_TRACK_ADVICE",
"name": "SMS track advice"
},
{
"code": "INT_EXTRA_COVER",
"name": "Extra Cover"
}
]
}
},
{
"code": "INT_PARCEL_STD_OWN_PACKAGING",
"name": "Standard",
"price": "31.40",
"max_extra_cover": 5000,
"options": {
"option": [
{
"code": "INT_TRACKING",
"name": "Tracking"
},
{
"code": "INT_EXTRA_COVER",
"name": "Extra Cover"
},
{
"code": "INT_SIGNATURE_ON_DELIVERY",
"name": "Signature on delivery"
},
{
"code": "INT_SMS_TRACK_ADVICE",
"name": "SMS track advice"
}
]
}
},
{
"code": "INT_PARCEL_AIR_OWN_PACKAGING",
"name": "Economy Air Parcels",
"price": "23.77",
"max_extra_cover": 500,
"options": {
"option": [
{
"code": "INT_EXTRA_COVER",
"name": "Extra Cover"
},
{
"code": "INT_SIGNATURE_ON_DELIVERY",
"name": "Signature on delivery"
}
]
}
}
]
}
}
Now how to extract the "name": "Express", "price": "40.13", from this variable? I would like to take the express, standard, Economy Air Parcels price. Please help me how to extract the exact data from this json mixed data
var text = '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}';
var obj = JSON.parse(text);
document.getElementById("demo").innerHTML =
obj.name + "<br>" +
obj.street + "<br>" +
obj.phone;
You can use this method.

Json Schema - Validate an infinite recursive structure

I'm trying to validate a json object using the "justinrainbow/json-schema" package for php.
Here's the json that i'm trying to validate:
{
"questions": [
{
"type": "section",
"name": "Section one",
"questions": [
{
"type": "section",
"name": "Subsection 1.1"
"questions":[
{
"type": "section",
"name": "Subsection 1.1"
"questions":
[
{
...
}
]
}
]
}
]
}
]
The questions property can always be present inside questions property ....
How can i validate it?
Thank you for your answers
You can use $ref to define a recursive structure.
{
"type": "object",
"properties": {
"type": { "type": "string" },
"name": { "type": "string" },
"questions": { "type": "array", "items": { "$ref": "#"} }
}
}

Categories