{"record":{"id":"22c612f7762e9c9f","repo":"plotly/plotly.js","slug":"api-call-to-plotly-method-rejected","errorCode":null,"errorMessage":"API call to Plotly.${method} rejected.","messagePattern":"API call to Plotly\\.(.+?) rejected\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/plots/command.js","lineNumber":265,"sourceCode":" * @param {string} method\n *      The name of the plotly command to execute. Must be one of 'animate',\n *      'restyle', 'relayout', 'update'.\n * @param {array} args\n *      A list of arguments passed to the API command\n */\nexports.executeAPICommand = function(gd, method, args) {\n    if(method === 'skip') return Promise.resolve();\n\n    var _method = Registry.apiMethodRegistry[method];\n    var allArgs = [gd];\n    if(!Array.isArray(args)) args = [];\n\n    for(var i = 0; i < args.length; i++) {\n        allArgs.push(args[i]);\n    }\n\n    return _method.apply(null, allArgs).catch(function(err) {\n        Lib.warn('API call to Plotly.' + method + ' rejected.', err);\n        return Promise.reject(err);\n    });\n};\n\nexports.computeAPICommandBindings = function(gd, method, args) {\n    var bindings;\n\n    if(!Array.isArray(args)) args = [];\n\n    switch(method) {\n        case 'restyle':\n            bindings = computeDataBindings(gd, args);\n            break;\n        case 'relayout':\n            bindings = computeLayoutBindings(gd, args);\n            break;\n        case 'update':\n            bindings = computeDataBindings(gd, [args[0], args[2]])","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/plots/command.js#L247-L283","documentation":"Plotly.wrap API commands (Plotly.restyle, Plotly.relayout, etc.) are wrapped so that when the underlying promise rejects, a warning 'API call to Plotly.X rejected.' is logged and the original error is re-thrown via the returned promise. The library logs this to give context that the failure came from a public API entry point; the actual cause is the rejection reason carried along.","triggerScenarios":"Any call to a wrapped Plotly API method (e.g. Plotly.restyle(gd, 'x', [[bad]]), Plotly.relayout, Plotly.addTraces, Plotly.animate) whose internal promise rejects — typically invalid arguments, a missing/unresponsive graph div, or an error thrown inside a reactive plotting step.","commonSituations":"Passing a non-DOM element or detached div as gd; invalid trace/attribute values caught during Plots.react; calling Plotly.newPlot on a container that was removed from the document mid-call; promise rejection from Plotly.purge-then-call sequences.","solutions":["Inspect the second argument of the warning (the rejection reason) — it holds the real error; fix the root cause there.","Validate arguments before calling: ensure gd is a div already passed through Plotly.newPlot and that attributes exist in the schema (check test/plot-schema.json or the reference page).","Await each API call and handle rejection: wrap the call in try/catch with async/await or .catch to control the failure.","If the div can be removed by React/framework unmounting, guard with document.body.contains(gd) before calling.","Upgrade plotly.js if the rejection is caused by a fixed upstream bug."],"exampleFix":"// before\nPlotly.restyle(gd, 'marker.color', 'not-a-color');\n// after\ntry {\n  await Plotly.restyle(gd, 'marker.color', '#ff0000');\n} catch (err) {\n  console.error('restyle failed:', err); // real cause\n}","handlingStrategy":"try-catch","validationCode":"async function safeRestyle(gd, ...args) {\n  if (!gd || !gd.classList || !gd.classList.contains('js-plotly-plot')) {\n    throw new Error('gd is not an initialized plotly graph div');\n  }\n  return Plotly.restyle(gd, ...args);\n}","typeGuard":"function isGraphDiv(el) {\n  return el instanceof HTMLElement && typeof el._fullLayout === 'object' && el._fullLayout !== null;\n}","tryCatchPattern":"try {\n  await Plotly.restyle(gd, update);\n} catch (err) {\n  console.warn('Plotly API call rejected:', err); // err is the root cause logged by the wrapper\n}","preventionTips":["Always await Plotly API promises instead of fire-and-forget calls.","Validate update attribute names against the plotly.js schema/reference before restyle/relayout.","Check the graph div is attached to the document before calling APIs.","Read the second argument of the 'rejected' warning — it contains the real cause."],"tags":["promise-rejection","api","plotly"],"backgroundTag":"unhandled-promise-rejection","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}