Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

ServiceNow (Flow Designer / Action)

manale460681490
Tera Contributor

 

Bonjour,

Je suis en train d’intégrer ServiceNow (Flow Designer / Action) avec Phenix Data Storage Partners v2 (gateway-http-v2) pour pousser des équipements.

Contexte

  • subject : raw-sites-click-repair-equipment-asset

  • schemaId : 00000000-2259-ba48-0000-000000000001

  • env test : INT

  • URL appelée :*****//partners-int.np.apimx.*****.fr/retail/v2/data_ingestion/pipeline/subject/raw-sites-click-repair-equipment-asset

J’ai eu au début un 401 (problème d’abonnement / credentials). Après abonnement, l’auth passe, mais j’ai maintenant un 400.


Erreur reçue

HTTP 400 avec :

  • "developerMessage": "Payload must be a JSON object, not a primitive type."
    ou parfois :

  • "developerMessage": "Invalid JSON"


Configuration REST Step (ServiceNow)

  • Method : POST

  • Request Type : Text

  • Request Body [Text] : Step 3 -> requestbody (String)

Headers :

  • Accept: application/json

  • Content-Type: application/vnd.phenix.gateway.json+json

  • x-*****-client-id: {{CLIENT_ID}}

  • x-*****-client-secret: {{CLIENT_SECRET}}


Payload que je vise

 

 
{ "messages": [ { "metadata": { "partitioningKey": "...", "schemaId": "...", "correlationId": "..." }, "data": "..." } ] }

 

 

Script Step (construction du payload)

Je construis messages[] et data = base64(JSON d’un objet equipment, pas un array).

 

 
(function execute(inputs, outputs) { var gr = inputs.equipments; var messages = []; var count = 0; function toIsoRfc3339Utc(gdtValue) { if (!gdtValue) return ""; var gdt = new GlideDateTime(gdtValue); return gdt.getValue().replace(" ", "T") + "Z"; } function toDateOnly(gdtValue) { if (!gdtValue) return ""; var gdt = new GlideDateTime(gdtValue); return gdt.getDate().getByFormat("yyyy-MM-dd"); } function toInt(val) { if (val === null || val === undefined || val === "") return null; var n = parseInt(val, 10); return isNaN(n) ? null : n; } function toBool(val) { return (val === true || val === "true" || val === "1" || val === 1); } if (!gr || typeof gr.next !== "function") { outputs.count = 0; outputs.requestbody = JSON.stringify({ messages: [] }); return; } while (gr.next()) { var equipmentObj = { u_id: gr.getValue("u_id") || "", asset_tag: gr.getValue("asset_tag") || "", u_commissioning_date: toDateOnly(gr.getValue("u_commissioning_date")), sys_created_on: toIsoRfc3339Utc(gr.getValue("sys_created_on")), u_denomination_code_asset: gr.getValue("u_denomination_code_asset") || "", display_name: gr.getDisplayValue() || "", u_denomination_equipement: gr.getValue("u_denomination_equipement") || "", u_name: gr.getValue("u_name") || "", u_manufacturing_date: toDateOnly(gr.getValue("u_manufacturing_date")), u_marque: gr.getValue("u_marque") || "", model: gr.getDisplayValue("model") || gr.getValue("model") || "", model_category: gr.getDisplayValue("model_category") || gr.getValue("model_category") || "", u_model_equipement: gr.getValue("u_model_equipement") || "", u_model_preventif: gr.getValue("u_model_preventif") || "", quantity: toInt(gr.getValue("quantity")) || 1, u_ra_ignore: toBool(gr.getValue("u_ra_ignore")), u_rayon_zone: gr.getValue("u_rayon_zone") || "", serial_number: gr.getValue("serial_number") || "", u_skills: [], install_status: toInt(gr.getValue("install_status")), substatus: gr.getValue("substatus") || "", u_type: gr.getValue("u_type") || "", sys_updated_on: toIsoRfc3339Utc(gr.getValue("sys_updated_on")), warranty_expiration: toDateOnly(gr.getValue("warranty_expiration")), u_warranty_duration: toInt(gr.getValue("u_warranty_duration")), department: gr.getDisplayValue("department") || gr.getValue("department") || "", additionnal_attributes: [] }; var base64Data = GlideStringUtil.base64Encode(JSON.stringify(equipmentObj)); messages.push({ metadata: { partitioningKey: equipmentObj.u_id || equipmentObj.asset_tag || gs.generateGUID(), schemaId: inputs.schema_id, correlationId: gs.generateGUID() }, data: base64Data }); count++; } outputs.count = count; outputs.requestbody = JSON.stringify({ messages: messages }); })(inputs, outputs);
 

 

0 REPLIES 0