{
  "info": {
    "name": "Suger co-sell referral API",
    "description": "WARNING: this collection is not a dry run, and it points at the production API. Every pass creates a real co-sell referral, submits it to AWS ACE / Microsoft Partner Center, and deletes it again -- so point `orgId` at a sandbox organization, or a real partner's pipeline receives it. One change outlives the pass: the AWS update step edits the standing referral you point `awsApprovedReferralId` at, not the one it just created, overwriting that referral's close date, next steps and expected customer spend in ACE. Nothing restores it.\n\nValidates, creates, fetches, lists, updates and previews a co-sell referral for AWS and for Azure, then deletes it. Needs an environment with `baseUrl` (https://api.suger.cloud), The API key needs all five of `cosell.read_referral`, `cosell.create_referral`, `cosell.edit_referral`, `cosell.delete_referral` and `operation.read`; a narrower key fails partway through the flow with a 403.\n\n`orgId`, `apiKey`, `salesforceOpportunityId` (a Salesforce Opportunity id from the organization's connected Salesforce) and `awsApprovedReferralId` (an AWS referral AWS has already approved: ACE refuses updates while an opportunity is under review, which every new one is, so the AWS update step edits that referral). Each request's description explains its body; the OpenAPI reference carries the same examples.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "apikey",
    "apikey": [
      {
        "key": "key",
        "value": "Authorization"
      },
      {
        "key": "value",
        "value": "Key {{apiKey}}"
      },
      {
        "key": "in",
        "value": "header"
      }
    ]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "if (pm.collectionVariables.get('pollOwner') !== pm.info.requestId) {",
          "  pm.collectionVariables.unset('pollTries');",
          "  pm.collectionVariables.unset('pollOwner');",
          "}",
          "const ensure = (key, make) => { if (!pm.variables.get(key)) pm.collectionVariables.set(key, make()); };",
          "const close = new Date(Date.now() + 90 * 864e5).toISOString().slice(0, 10);",
          "if (!pm.variables.get('closeDate') || pm.variables.get('closeDate') < new Date().toISOString().slice(0, 10)) {",
          "  pm.collectionVariables.set('closeDate', close);",
          "  pm.collectionVariables.set('closeDateTime', close + 'T00:00:00Z');",
          "}",
          "ensure('awsReferralId', () => pm.variables.replaceIn('{{$guid}}'));",
          "ensure('azureReferralId', () => pm.variables.replaceIn('{{$guid}}'));",
          "// ACE rejects an opportunity matching an existing one as a Duplicate Record, so",
          "// each run names a different customer.",
          "ensure('runTag', () => pm.variables.replaceIn('{{$guid}}').slice(0, 8));"
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "closeDate",
      "value": ""
    },
    {
      "key": "closeDateTime",
      "value": ""
    },
    {
      "key": "awsReferralId",
      "value": ""
    },
    {
      "key": "azureReferralId",
      "value": ""
    },
    {
      "key": "runTag",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "AWS",
      "item": [
        {
          "name": "AWS: Validate the opportunity",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "['awsReferralId', 'awsReferralIdStored', 'updateOperationId', 'pollTries', 'pollOwner']",
                  "  .forEach((key) => pm.collectionVariables.unset(key));",
                  "pm.collectionVariables.set('awsReferralId', pm.variables.replaceIn('{{$guid}}'));",
                  "pm.collectionVariables.set('runTag', pm.variables.replaceIn('{{$guid}}').slice(0, 8));"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "pm.test('passes partner validation', () => {",
                  "  const r = pm.response.json();",
                  "  pm.expect(r.valid, JSON.stringify(r.errors)).to.be.true;",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/validate",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "validate"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"partner\": \"AWS\",\n  \"opportunity\": {\n    \"Customer\": {\n      \"Account\": {\n        \"CompanyName\": \"Contoso Analytics {{runTag}}\",\n        \"Industry\": \"Software and Internet\",\n        \"WebsiteUrl\": \"https://contoso-analytics-{{runTag}}.example.com\",\n        \"Address\": {\n          \"CountryCode\": \"US\",\n          \"PostalCode\": \"94105\",\n          \"StateOrRegion\": \"California\",\n          \"City\": \"San Francisco\"\n        }\n      },\n      \"Contacts\": [\n        {\n          \"Email\": \"jamie.lee@contoso-analytics.example.com\",\n          \"FirstName\": \"Jamie\",\n          \"LastName\": \"Lee\",\n          \"BusinessTitle\": \"VP Engineering\"\n        }\n      ]\n    },\n    \"PrimaryNeedsFromAws\": [\n      \"Co-Sell - Technical Consultation\"\n    ],\n    \"OpportunityType\": \"Net New Business\",\n    \"Project\": {\n      \"Title\": \"Contoso Analytics - data platform migration {{runTag}}\",\n      \"CustomerBusinessProblem\": \"Contoso runs its analytics stack in a colocation data center that is reaching end of life and wants to move it to AWS before renewal.\",\n      \"CustomerUseCase\": \"Migration / Database Migration\",\n      \"DeliveryModels\": [\n        \"SaaS or PaaS\"\n      ],\n      \"ExpectedCustomerSpend\": [\n        {\n          \"Amount\": \"15000\",\n          \"CurrencyCode\": \"USD\",\n          \"Frequency\": \"Monthly\",\n          \"TargetCompany\": \"AWS\"\n        }\n      ],\n      \"SalesActivities\": [\n        \"Initialized discussions with customer\"\n      ]\n    },\n    \"RelatedEntityIdentifiers\": {\n      \"Solutions\": [\n        \"S-0060105\"\n      ]\n    },\n    \"LifeCycle\": {\n      \"TargetCloseDate\": \"{{closeDate}}\"\n    }\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "`ValidateReferral`: Dry-run an AWS opportunity. `opportunity` is the bare partner object -- for AWS the `aceOpportunityV2` value, not a whole referral. Nothing is created. Unlike CreateCosellReferral, no missing fields are filled in for you."
          }
        },
        {
          "name": "AWS: Create the referral",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"{{awsReferralId}}\",\n  \"partner\": \"AWS\",\n  \"info\": {\n    \"aceOpportunityV2\": {\n      \"Customer\": {\n        \"Account\": {\n          \"CompanyName\": \"Contoso Analytics {{runTag}}\",\n          \"Industry\": \"Software and Internet\",\n          \"WebsiteUrl\": \"https://contoso-analytics-{{runTag}}.example.com\",\n          \"Address\": {\n            \"CountryCode\": \"US\",\n            \"PostalCode\": \"94105\",\n            \"StateOrRegion\": \"California\",\n            \"City\": \"San Francisco\"\n          }\n        },\n        \"Contacts\": [\n          {\n            \"Email\": \"jamie.lee@contoso-analytics.example.com\",\n            \"FirstName\": \"Jamie\",\n            \"LastName\": \"Lee\",\n            \"BusinessTitle\": \"VP Engineering\"\n          }\n        ]\n      },\n      \"PrimaryNeedsFromAws\": [\n        \"Co-Sell - Technical Consultation\"\n      ],\n      \"OpportunityType\": \"Net New Business\",\n      \"Project\": {\n        \"Title\": \"Contoso Analytics - data platform migration {{runTag}}\",\n        \"CustomerBusinessProblem\": \"Contoso runs its analytics stack in a colocation data center that is reaching end of life and wants to move it to AWS before renewal.\",\n        \"CustomerUseCase\": \"Migration / Database Migration\",\n        \"DeliveryModels\": [\n          \"SaaS or PaaS\"\n        ],\n        \"ExpectedCustomerSpend\": [\n          {\n            \"Amount\": \"15000\",\n            \"CurrencyCode\": \"USD\",\n            \"Frequency\": \"Monthly\",\n            \"TargetCompany\": \"AWS\"\n          }\n        ],\n        \"SalesActivities\": [\n          \"Initialized discussions with customer\"\n        ]\n      },\n      \"RelatedEntityIdentifiers\": {\n        \"Solutions\": [\n          \"S-0060105\"\n        ]\n      },\n      \"LifeCycle\": {\n        \"TargetCloseDate\": \"{{closeDate}}\"\n      }\n    }\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "`CreateCosellReferral`: AWS ACE opportunity. Shares a partner-sourced opportunity with AWS. `id` is optional and is yours to choose: any string of at most 36 characters, unique in your organization (a UUID is generated when omitted). Send it so a retry can be matched to the first attempt -- see the operation description before retrying. `RelatedEntityIdentifiers.Solutions` takes your ACE solution ids (`S-` followed by digits)."
          }
        },
        {
          "name": "AWS: Wait for the partner submission",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Every retry of this request waits 5s first.",
                  "if (Number(pm.collectionVariables.get('pollTries') || 0) > 0) setTimeout(() => {}, 5000);"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "if (pm.response.code !== 200) { pm.collectionVariables.unset('pollTries'); return; }",
                  "const r = pm.response.json();",
                  "const tries = Number(pm.collectionVariables.get('pollTries') || 0);",
                  "if (r.status === 'PENDING_CREATE' && tries < 24) {",
                  "  pm.collectionVariables.set('pollTries', tries + 1);",
                  "  pm.collectionVariables.set('pollOwner', pm.info.requestId);",
                  "  pm.execution.setNextRequest(pm.info.requestId);",
                  "} else {",
                  "  pm.collectionVariables.unset('pollTries');",
                  "  pm.collectionVariables.unset('pollOwner');",
                  "  pm.test('was submitted to the partner', () =>",
                  "    pm.expect(r.status, JSON.stringify(r.errorMessages)).to.be.oneOf(",
                  "      ['DRAFT', 'IN_REVIEW', 'PENDING_ACCEPTANCE', 'ACTION_REQUIRED', 'ACTIVE']));",
                  "  pm.test('is the referral that was created', () => pm.expect(r.id).to.eql(pm.variables.get('awsReferralId')));",
                  "  pm.collectionVariables.set('awsReferralIdStored', JSON.stringify(r));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/{{awsReferralId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "{{awsReferralId}}"
              ]
            },
            "description": "`GetCosellReferral`"
          }
        },
        {
          "name": "AWS: List referrals",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "pm.test('returns a page of referrals', () => pm.expect(pm.response.json().data).to.be.an('array'));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral?page_size=10",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral"
              ],
              "query": [
                {
                  "key": "page_size",
                  "value": "10"
                }
              ]
            },
            "description": "`ListCosellReferrals`"
          }
        },
        {
          "name": "AWS: Update the referral",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "// The update answers once it is saved; the push to the partner runs on as this operation.",
                  "const workflowID = pm.response.json().workflowID;",
                  "pm.test('returns the partner sync operation', () => pm.expect(workflowID).to.be.a('string').that.is.not.empty);",
                  "pm.collectionVariables.set('updateOperationId', encodeURIComponent(workflowID || ''));"
                ]
              }
            }
          ],
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/{{awsApprovedReferralId}}?merge=true",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "{{awsApprovedReferralId}}"
              ],
              "query": [
                {
                  "key": "merge",
                  "value": "true"
                }
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"partner\": \"AWS\",\n  \"info\": {\n    \"aceOpportunityV2\": {\n      \"LifeCycle\": {\n        \"TargetCloseDate\": \"{{closeDate}}\",\n        \"NextSteps\": \"Technical deep dive with the customer's data team scheduled.\"\n      },\n      \"Project\": {\n        \"ExpectedCustomerSpend\": [\n          {\n            \"Amount\": \"20000\",\n            \"CurrencyCode\": \"USD\",\n            \"Frequency\": \"Monthly\",\n            \"TargetCompany\": \"AWS\"\n          }\n        ]\n      }\n    }\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "`UpdateCosellReferral`: AWS partial update (send with ?merge=true). With `merge=true` send only what changes, plus `partner`. Omitted fields keep their stored values, an explicit `null` clears a field, objects merge key by key, and lists such as `Contacts` or `Solutions` are replaced whole, so send the complete list when you change one. Use the same spelling GetCosellReferral returns (PascalCase); sending one field under two spellings is rejected."
          }
        },
        {
          "name": "AWS: Wait for the update to reach the partner",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get('updateOperationId')) {",
                  "  console.warn('no sync operation from the update step; skipping this poll');",
                  "  pm.execution.skipRequest();",
                  "}",
                  "if (Number(pm.collectionVariables.get('pollTries') || 0) > 0) setTimeout(() => {}, 5000);"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "if (pm.response.code !== 200) { pm.collectionVariables.unset('pollTries'); return; }",
                  "const op = pm.response.json();",
                  "const tries = Number(pm.collectionVariables.get('pollTries') || 0);",
                  "if (op.status === 'Running' && tries < 24) {",
                  "  pm.collectionVariables.set('pollTries', tries + 1);",
                  "  pm.collectionVariables.set('pollOwner', pm.info.requestId);",
                  "  pm.execution.setNextRequest(pm.info.requestId);",
                  "} else {",
                  "  pm.collectionVariables.unset('pollTries');",
                  "  pm.collectionVariables.unset('pollOwner');",
                  "  pm.test('reached the partner', () => pm.expect(op.status, op.message).to.eql('Completed'));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/v2/operation/{{updateOperationId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "v2",
                "operation",
                "{{updateOperationId}}"
              ]
            },
            "description": "`GetOperationV2`"
          }
        },
        {
          "name": "AWS: Preview a Salesforce opportunity",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "pm.test('returns one mapped referral per CRM record', () => pm.expect(pm.response.json()).to.have.lengthOf(1));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/batchPreview",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "batchPreview"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"partner\": \"AWS\",\n  \"crmPartner\": \"SALESFORCE\",\n  \"crmRecordIds\": [\n    \"{{salesforceOpportunityId}}\"\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "`BatchPreviewCosellReferrals`: Preview Salesforce opportunities as AWS referrals. Maps each Salesforce Opportunity onto an AWS opportunity using the organization's field mapping and returns the result without creating anything. Pass a returned referral to ValidateReferral, then to CreateCosellReferral."
          }
        },
        {
          "name": "AWS: Delete the referral",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "pm.collectionVariables.unset('awsReferralId');",
                  "pm.collectionVariables.unset('awsReferralIdStored');",
                  "pm.collectionVariables.unset('runTag');"
                ]
              }
            }
          ],
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/{{awsReferralId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "{{awsReferralId}}"
              ]
            },
            "description": "`DeleteCosellReferral`"
          }
        }
      ]
    },
    {
      "name": "Azure (partner-led)",
      "item": [
        {
          "name": "Azure (partner-led): Validate the opportunity",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "['azureReferralId', 'azureReferralIdStored', 'updateOperationId', 'pollTries', 'pollOwner']",
                  "  .forEach((key) => pm.collectionVariables.unset(key));",
                  "pm.collectionVariables.set('azureReferralId', pm.variables.replaceIn('{{$guid}}'));",
                  "pm.collectionVariables.set('runTag', pm.variables.replaceIn('{{$guid}}').slice(0, 8));"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "pm.test('passes partner validation', () => {",
                  "  const r = pm.response.json();",
                  "  pm.expect(r.valid, JSON.stringify(r.errors)).to.be.true;",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/validate",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "validate"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"partner\": \"AZURE\",\n  \"opportunity\": {\n    \"name\": \"Contoso Analytics - AI assistant rollout\",\n    \"customerProfile\": {\n      \"name\": \"Contoso Analytics\",\n      \"address\": {\n        \"country\": \"US\",\n        \"city\": \"San Francisco\",\n        \"state\": \"CA\",\n        \"postalCode\": \"94105\"\n      }\n    },\n    \"team\": [\n      {\n        \"email\": \"alex.morgan@your-company.example.com\",\n        \"firstName\": \"Alex\",\n        \"lastName\": \"Morgan\",\n        \"phoneNumber\": \"+14155550100\"\n      }\n    ],\n    \"details\": {\n      \"closingDateTime\": \"{{closeDateTime}}\",\n      \"dealValue\": 50000,\n      \"currency\": \"USD\",\n      \"requirements\": {\n        \"solutions\": [\n          {\n            \"id\": \"7c574f32-b3ce-44fb-bb8b-bfe11d71a07a\"\n          }\n        ],\n        \"additionalRequirements\": {\n          \"attributes\": [\n            {\n              \"type\": \"SolutionArea\",\n              \"id\": \"AI Business Solutions\"\n            },\n            {\n              \"type\": \"Conversation\",\n              \"id\": \"AI-ready productivity and security for every employee\"\n            },\n            {\n              \"type\": \"CustomerMarketplaceIntent\",\n              \"id\": \"HaveNotDecided\"\n            }\n          ]\n        }\n      }\n    },\n    \"invitations\": [\n      {\n        \"organizationId\": \"msft\",\n        \"assistanceRequestCode\": \"NoHelpRequired\"\n      }\n    ]\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "`ValidateReferral`: Dry-run an Azure create request. For Azure `opportunity` is the `createMicrosoftReferralRequest` value. The verdict is strict: values CreateCosellReferral would fill in for you (country, currency, phone, marketplace intent) are reported missing here; `normalizedOpportunity` in the response shows the filled-in version."
          }
        },
        {
          "name": "Azure (partner-led): Create the referral",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"{{azureReferralId}}\",\n  \"partner\": \"AZURE\",\n  \"info\": {\n    \"createMicrosoftReferralRequest\": {\n      \"name\": \"Contoso Analytics - AI assistant rollout\",\n      \"customerProfile\": {\n        \"name\": \"Contoso Analytics\",\n        \"address\": {\n          \"country\": \"US\",\n          \"city\": \"San Francisco\",\n          \"state\": \"CA\",\n          \"postalCode\": \"94105\"\n        }\n      },\n      \"team\": [\n        {\n          \"email\": \"alex.morgan@your-company.example.com\",\n          \"firstName\": \"Alex\",\n          \"lastName\": \"Morgan\",\n          \"phoneNumber\": \"+14155550100\"\n        }\n      ],\n      \"details\": {\n        \"closingDateTime\": \"{{closeDateTime}}\",\n        \"dealValue\": 50000,\n        \"currency\": \"USD\",\n        \"requirements\": {\n          \"solutions\": [\n            {\n              \"id\": \"7c574f32-b3ce-44fb-bb8b-bfe11d71a07a\"\n            }\n          ],\n          \"additionalRequirements\": {\n            \"attributes\": [\n              {\n                \"type\": \"SolutionArea\",\n                \"id\": \"AI Business Solutions\"\n              },\n              {\n                \"type\": \"Conversation\",\n                \"id\": \"AI-ready productivity and security for every employee\"\n              },\n              {\n                \"type\": \"CustomerMarketplaceIntent\",\n                \"id\": \"HaveNotDecided\"\n              }\n            ]\n          }\n        }\n      },\n      \"invitations\": [\n        {\n          \"organizationId\": \"msft\",\n          \"assistanceRequestCode\": \"NoHelpRequired\"\n        }\n      ]\n    }\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "`CreateCosellReferral`: Azure Partner Center referral, partner-led (no Microsoft help). An Azure create reads `info.createMicrosoftReferralRequest`, not the `info.microsoftReferralSet` that GetCosellReferral returns, so do not resubmit a fetched body as-is. Partner-led means the only Microsoft invitation uses `assistanceRequestCode` `NoHelpRequired` (or there is none): the referral is created as type `Independent` with deal type `Private`. `details.requirements.solutions[].id` comes from AzureMicrosoftSolutionLookup or AzureThirdPartySolutionLookup."
          }
        },
        {
          "name": "Azure (partner-led): Wait for the partner submission",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// Every retry of this request waits 5s first.",
                  "if (Number(pm.collectionVariables.get('pollTries') || 0) > 0) setTimeout(() => {}, 5000);"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "if (pm.response.code !== 200) { pm.collectionVariables.unset('pollTries'); return; }",
                  "const r = pm.response.json();",
                  "const tries = Number(pm.collectionVariables.get('pollTries') || 0);",
                  "if (r.status === 'PENDING_CREATE' && tries < 24) {",
                  "  pm.collectionVariables.set('pollTries', tries + 1);",
                  "  pm.collectionVariables.set('pollOwner', pm.info.requestId);",
                  "  pm.execution.setNextRequest(pm.info.requestId);",
                  "} else {",
                  "  pm.collectionVariables.unset('pollTries');",
                  "  pm.collectionVariables.unset('pollOwner');",
                  "  pm.test('was submitted to the partner', () =>",
                  "    pm.expect(r.status, JSON.stringify(r.errorMessages)).to.be.oneOf(",
                  "      ['DRAFT', 'IN_REVIEW', 'PENDING_ACCEPTANCE', 'ACTION_REQUIRED', 'ACTIVE']));",
                  "  pm.test('is the referral that was created', () => pm.expect(r.id).to.eql(pm.variables.get('azureReferralId')));",
                  "  pm.collectionVariables.set('azureReferralIdStored', JSON.stringify(r));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/{{azureReferralId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "{{azureReferralId}}"
              ]
            },
            "description": "`GetCosellReferral`"
          }
        },
        {
          "name": "Azure (partner-led): List referrals",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "pm.test('returns a page of referrals', () => pm.expect(pm.response.json().data).to.be.an('array'));"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral?page_size=10",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral"
              ],
              "query": [
                {
                  "key": "page_size",
                  "value": "10"
                }
              ]
            },
            "description": "`ListCosellReferrals`"
          }
        },
        {
          "name": "Azure (partner-led): Update the referral",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const stored = pm.collectionVariables.get('azureReferralIdStored');",
                  "const referral = stored ? JSON.parse(stored) : null;",
                  "const self = referral && referral.info && referral.info.microsoftReferralSet",
                  "  ? referral.info.microsoftReferralSet.self : null;",
                  "if (!self || !self.details) {",
                  "  pm.execution.skipRequest();",
                  "} else {",
                  "  self.details.notes = 'Updated by the co-sell referral API collection.';",
                  "  pm.request.body.raw = JSON.stringify(referral, null, 2);",
                  "}"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "// The update answers once it is saved; the push to the partner runs on as this operation.",
                  "const workflowID = pm.response.json().workflowID;",
                  "pm.test('returns the partner sync operation', () => pm.expect(workflowID).to.be.a('string').that.is.not.empty);",
                  "pm.collectionVariables.set('updateOperationId', encodeURIComponent(workflowID || ''));"
                ]
              }
            }
          ],
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/{{azureReferralId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "{{azureReferralId}}"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"{{azureReferralId}}\",\n  \"partner\": \"AZURE\",\n  \"externalId\": \"cac7e466-4a26-483c-8fbb-674b183b0fc5\",\n  \"salesforceOpportunityId\": \"006Oy00000OerZFIAZ\",\n  \"salesforceAccountId\": \"\",\n  \"salesforceReferralId\": \"\",\n  \"hubspotDealId\": \"\",\n  \"dynamics365OpportunityId\": \"\",\n  \"info\": {\n    \"microsoftReferralSet\": {\n      \"self\": {\n        \"id\": \"cac7e466-4a26-483c-8fbb-674b183b0fc5\",\n        \"engagementId\": \"58d51d0f-42c7-46e0-bb62-1f5bb7b3068c\",\n        \"name\": \"Contoso Analytics - AI assistant rollout\",\n        \"status\": \"Active\",\n        \"substatus\": \"Accepted\",\n        \"salesStage\": \"20\",\n        \"type\": \"Independent\",\n        \"direction\": \"Outgoing\",\n        \"qualification\": \"SalesQualified\",\n        \"externalReferenceId\": \"006Oy00000OerZFIAZ\",\n        \"customerProfile\": {\n          \"name\": \"Contoso Analytics\",\n          \"address\": {\n            \"country\": \"US\",\n            \"city\": \"San Francisco\",\n            \"state\": \"CA\",\n            \"postalCode\": \"94105\"\n          }\n        },\n        \"consent\": {\n          \"consentToContact\": true,\n          \"consentToShareReferralWithMicrosoftSellers\": true,\n          \"consentToToShareInfoWithOthers\": true\n        },\n        \"team\": [\n          {\n            \"email\": \"alex.morgan@your-company.example.com\",\n            \"firstName\": \"Alex\",\n            \"lastName\": \"Morgan\",\n            \"phoneNumber\": \"+14155550100\"\n          }\n        ],\n        \"details\": {\n          \"closingDateTime\": \"2027-09-30T00:00:00Z\",\n          \"dealValue\": 75000,\n          \"currency\": \"USD\",\n          \"notes\": \"Customer confirmed budget for the next fiscal year.\",\n          \"requirements\": {\n            \"solutions\": [\n              {\n                \"id\": \"7c574f32-b3ce-44fb-bb8b-bfe11d71a07a\"\n              }\n            ],\n            \"additionalRequirements\": {\n              \"attributes\": [\n                {\n                  \"type\": \"SolutionArea\",\n                  \"id\": \"AI Business Solutions\"\n                },\n                {\n                  \"type\": \"Conversation\",\n                  \"id\": \"AI-ready productivity and security for every employee\"\n                },\n                {\n                  \"type\": \"CustomerMarketplaceIntent\",\n                  \"id\": \"HaveNotDecided\"\n                }\n              ]\n            }\n          }\n        },\n        \"target\": [\n          {\n            \"type\": \"SolutionProfile\",\n            \"id\": \"7c574f32-b3ce-44fb-bb8b-bfe11d71a07a\"\n          }\n        ]\n      }\n    }\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "`UpdateCosellReferral`: Azure full update (whole referral sent back). Azure has no partial update (`merge=true` returns 400): the body replaces the stored referral. Fetch it with GetCosellReferral, change what you need under `info.microsoftReferralSet.self`, and send the whole referral back with `partner` AZURE. Read-only fields (including `id`, `engagementId`, `type`, `eTag`, `organizationId`, `mpnId` and timestamps) are kept from the stored copy whatever you send, and `status`, `substatus` and `salesStage` must be echoed or the update is rejected. Anything else you omit is dropped, so send back the body GetCosellReferral returned with your edit applied; do not assemble a minimal one. The operation description lists what an omission costs."
          }
        },
        {
          "name": "Azure (partner-led): Wait for the update to reach the partner",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get('updateOperationId')) {",
                  "  console.warn('no sync operation from the update step; skipping this poll');",
                  "  pm.execution.skipRequest();",
                  "}",
                  "if (Number(pm.collectionVariables.get('pollTries') || 0) > 0) setTimeout(() => {}, 5000);"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "if (pm.response.code !== 200) { pm.collectionVariables.unset('pollTries'); return; }",
                  "const op = pm.response.json();",
                  "const tries = Number(pm.collectionVariables.get('pollTries') || 0);",
                  "if (op.status === 'Running' && tries < 24) {",
                  "  pm.collectionVariables.set('pollTries', tries + 1);",
                  "  pm.collectionVariables.set('pollOwner', pm.info.requestId);",
                  "  pm.execution.setNextRequest(pm.info.requestId);",
                  "} else {",
                  "  pm.collectionVariables.unset('pollTries');",
                  "  pm.collectionVariables.unset('pollOwner');",
                  "  pm.test('reached the partner', () => pm.expect(op.status, op.message).to.eql('Completed'));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/v2/operation/{{updateOperationId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "v2",
                "operation",
                "{{updateOperationId}}"
              ]
            },
            "description": "`GetOperationV2`"
          }
        },
        {
          "name": "Azure (partner-led): Preview a Salesforce opportunity",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "pm.test('returns one mapped referral per CRM record', () => pm.expect(pm.response.json()).to.have.lengthOf(1));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/batchPreview",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "batchPreview"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"partner\": \"AZURE\",\n  \"crmPartner\": \"SALESFORCE\",\n  \"crmRecordIds\": [\n    \"{{salesforceOpportunityId}}\"\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "description": "`BatchPreviewCosellReferrals`: Preview Salesforce opportunities as Azure referrals. Same request as the AWS folder's preview with `partner` set to AZURE: each Salesforce Opportunity is mapped onto an Azure referral using the organization's field mapping and returned without creating anything."
          }
        },
        {
          "name": "Azure (partner-led): Delete the referral",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('returns 200', () => pm.response.to.have.status(200));",
                  "pm.collectionVariables.unset('azureReferralId');",
                  "pm.collectionVariables.unset('azureReferralIdStored');",
                  "pm.collectionVariables.unset('runTag');"
                ]
              }
            }
          ],
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/org/{{orgId}}/cosell/referral/{{azureReferralId}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "org",
                "{{orgId}}",
                "cosell",
                "referral",
                "{{azureReferralId}}"
              ]
            },
            "description": "`DeleteCosellReferral`"
          }
        }
      ]
    }
  ]
}
