Overview
The Orden Compra mutations provide functionality to create purchase orders from procurement requisitions and manage order status. These operations integrate with SAP procurement systems for order processing.
Available Mutations
CreateOcProcurment
Create a purchase order in the procurement system from an existing requisition (SOLPED).
Mutation Definition
mutation CreateOcProcurment (
$solped : String !
$proveedor : String !
$incoterm : String !
$organizacion : String !
$clasedocumento : String !
$items : [ ApiOcRequestDetailDto ! ] !
) {
createOcProcurment (
solped : $solped
proveedor : $proveedor
incoterm : $incoterm
organizacion : $organizacion
clasedocumento : $clasedocumento
items : $items
) {
success
hasErrorService
hasWarnings
responseUnparsed
response {
documento
return {
type
id
number
message
message_v1
message_v2
message_v3
message_v4
parameter
system
}
}
}
}
The SOLPED (requisition) number from which to create the purchase order.
The supplier/vendor code who will fulfill the order.
The INCOTERM (International Commercial Terms) that defines shipping and delivery responsibilities. Common values: FOB, CIF, EXW, DDP, etc.
The purchasing organization code in the SAP system.
The document class or type identifier for the purchase order.
items
[ApiOcRequestDetailDto!]!
required
An array of line items to include in the purchase order. Show ApiOcRequestDetailDto Fields
The position or line number of the item. This value will be automatically multiplied by 10 during processing.
The tax code (IVA/VAT code) applicable to this line item.
The ID of the requirement or requisition item this line fulfills.
Response Fields
Indicates whether the purchase order was successfully created. true if successful, false otherwise.
Indicates if there was an error communicating with the external procurement service.
Indicates if the operation completed but with warnings that should be reviewed.
The raw, unparsed response from the SAP procurement system for debugging purposes.
The parsed response from the procurement system. Show ApiOcResponse Fields
The document number or purchase order number assigned by SAP.
An array of return messages from the SAP system. Message type: S (Success), E (Error), W (Warning), I (Information).
Message ID for reference.
Message number within the system.
Additional message variable 1.
Additional message variable 2.
Additional message variable 3.
Additional message variable 4.
The parameter that triggered this message.
The source system that generated this message.
Example Request
mutation {
createOcProcurment (
solped : "4500123456"
proveedor : "PROV-001"
incoterm : "FOB"
organizacion : "ORG-100"
clasedocumento : "NB"
items : [
{
posicion : "1"
codiva : "V1"
idRequerimiento : 5001
},
{
posicion : "2"
codiva : "V1"
idRequerimiento : 5002
}
]
) {
success
hasErrorService
response {
documento
return {
type
message
}
}
}
}
Example Response (Success)
{
"data" : {
"createOcProcurment" : {
"success" : true ,
"hasErrorService" : false ,
"response" : {
"documento" : "4500789012" ,
"return" : [
{
"type" : "S" ,
"message" : "Purchase order 4500789012 created successfully"
}
]
}
}
}
}
Example Response (Error)
{
"data" : {
"createOcProcurment" : {
"success" : false ,
"hasErrorService" : false ,
"response" : {
"documento" : "" ,
"return" : [
{
"type" : "E" ,
"message" : "Supplier PROV-001 is blocked for purchasing organization ORG-100" ,
"parameter" : "PROVEEDOR"
}
]
}
}
}
}
DesbloquearPedido
Unblock a purchase order that has been blocked in the system.
Mutation Definition
mutation DesbloquearPedido ( $input : DesbloquearPedidoInput ! ) {
desbloquearPedido ( input : $input ) {
return {
type
id
number
message
message_v1
message_v2
message_v3
message_v4
parameter
system
}
}
}
input
DesbloquearPedidoInput
required
The input object containing the order information to unblock. Show DesbloquearPedidoInput Fields
The purchase order number (pedido) to unblock.
Response Fields
An array of messages returned from the unblock operation. Show PedidoMensaje Fields
Message type: S (Success), E (Error), W (Warning), I (Information).
Message ID for reference.
Message number within the system.
The main message text describing the result of the unblock operation.
Additional message variable 1.
Additional message variable 2.
Additional message variable 3.
Additional message variable 4.
The parameter related to this message.
The source system that generated this message.
Example Request
mutation {
desbloquearPedido ( input : { pedido : "4500789012" }) {
return {
type
message
parameter
}
}
}
Example Response (Success)
{
"data" : {
"desbloquearPedido" : {
"return" : [
{
"type" : "S" ,
"message" : "Order 4500789012 has been successfully unblocked" ,
"parameter" : null
}
]
}
}
}
Example Response (Error)
{
"data" : {
"desbloquearPedido" : {
"return" : [
{
"type" : "E" ,
"message" : "Order 4500789012 not found or already unblocked" ,
"parameter" : "PEDIDO"
}
]
}
}
}
Implementation Details
Authentication
Both mutations require proper authentication:
OAuth 2.0 Bearer token authentication
Tokens are obtained from the configured authentication service
Credentials are managed through appsettings.json configuration
Source Code References
CreateOcProcurment Mutation.cs:906-932 Handles position normalization (multiplying by 10) and calls the SAP procurement API.
DesbloquearPedido Schema/OrdenCompra/PedidoMutation.cs:16-30 Sends unblock requests to external service endpoint.
External Service Integration
CreateOcProcurment
Service : ApiOc (Helpers/Oc/ApiOc.cs:62)
Endpoint : Configured in ApiProcurmentReg:UrlOc
Method : POST
Authentication : OAuth 2.0 Client Credentials flow
DesbloquearPedido
Service : PedidoTrasladoService (Services/OrdenCompra/PedidoTrasladoService.cs:21)
Endpoint : Configured in urlDesbloqueoPedido:Url
Method : POST
Authentication : Bearer token via AuthService
Error Handling
Always check the hasErrorService and success flags in the response to determine if the operation completed successfully. The return array may contain multiple messages with different severity levels.
Common Error Types
E (Error) : Critical errors that prevented order creation
W (Warning) : The operation completed but with warnings
I (Information) : Informational messages about the process
S (Success) : Successful operation confirmation
Best Practices
Validate Input : Ensure all supplier codes, organization codes, and document classes exist in SAP before calling the mutation
Position Numbers : The system automatically multiplies position numbers by 10, so use sequential integers (1, 2, 3…)
Error Messages : Parse the return array to display all relevant messages to users
Idempotency : Check if an order already exists for the SOLPED before creating a new one
Logging : Store the responseUnparsed field for debugging and audit purposes
Use Cases
Procurement Automation
Automate purchase order creation from approved requisitions:
# After requisition approval
mutation AutoCreatePO ( $solpedId : String ! ) {
createOcProcurment (
solped : $solpedId
proveedor : "VENDOR-123"
incoterm : "CIF"
organizacion : "PURCHASING-ORG"
clasedocumento : "NB"
items : [
# Items from requisition
]
) {
success
response {
documento
}
}
}
Order Status Management
Unblock orders that were temporarily held:
mutation UnblockOrder ( $orderNumber : String ! ) {
desbloquearPedido ( input : { pedido : $orderNumber }) {
return {
type
message
}
}
}