I am trying to create a JSON structure to send API to a Mexican invoice provider (cfdi 3.3). I already have a function with the values of the items, with cfloop. The question is that I don't know how to insert in the same structure the other values that are not within the array "Items:", such as payment_type, customer, etc
This is the example of API request
curl https://www.facturapi.io/v1/invoices \
-u "sk_test_API_KEY:" \
-H "Content-Type: application / json" \
-d '{
"customer": "58e93ionede86eb318b0197456",
"items": [{
"quantity": 2,
"product": "58e93ionede86eb318b0197454"
}],
"payment_form": "06",
"folio_number": 914,
"series": "A"
} '
I want to get a structure like this:
{
"customer": "77e93ionede86eb318b0197456",
"items": [
{
"quantity": 2,
"product": "99e93etimee86eb318b0191111"
},
{
"quantity": 5,
"product": "88e55etimee86eb999b0192222"
}
],
"payment_form": "06",
"folio_number": 914,
"series": "A"
}
This is my code (cffunction)
<cfcomponent>
<cfset #dsnvtasmart# = "popmart">
<cffunction name="result" access="remote"
returntype="array"
returnformat="JSON"
hint="it is the text">
<cfset #dsnvtasmart# = "popmart">
<cfquery name="qProd" datasource="#dsnvtasmart#">
SELECT det_ordenp.cant AS quantity
, det_ordenp.api_id_prod AS product
FROM det_ordenp
WHERE det_ordenp.id_orden = #worden#
</cfquery>
<!---
**---Other values Json Struct.--------**
--->
<cfset customer =#77e93ionede86eb318b0197456#>
<cfset payment_form = '06'>
<cfset folio_number = 914>
<cfset series = 'A'>
<cfloop query="qProd">
<cfset var empStruct = {"quantity":#qProd.quantity#, "product":#qProd.product#}>
<cfset arrayAppend (result, empStruct)>
</cfloop>
<cfreturn result>
</cffunction>
</cfcomponent>
At the moment, with this code, I am only getting:
[
{
"quantity": 6,
"product": "5d5307eb8a6ce057e78b32be"
},
{
"quantity": 37,
"product": "5d53080d8a6ce057e78b32c0"
}
]
I have no idea how to include in empStruct, the values of :
{
"customer": "77e93ionede86eb318b0197456",
"payment_form": "06",
"folio_number": 914,
"series": "A"
}
I hope my question is readable, if anyone has a suggestion I would appreciate it.