Portal documentation via API

I am wondering if it is possible to upload Swagger documentation for API catalogues via the API? Is there any documentation for this process?

I would like to create an API catalog, apply a policy, and at the same time upload a swagger blob that describes the API, all via the API.

I inspected the network when I used the UI, and I see the swagger doc is converted to a JWT token.

Thanks
Bill

1.You need to create an api. You can do it via the ui by clicking add api or by clicking “import api” and paste the swagger file content in the box.
If it’s via swagger go through the paths in the endpoint designer and set the configuration you need.
2. Set the with on the api
3. Create a policy and add the api to it.
4. In the portal management create a catalogue and add that policy to it.
5. Click on import document and paste the swagger content in it.
https://tyk.io/docs/get-started/with-tyk-cloud/tutorials/create-portal-entry/

Note: In the swagger make sure the hose, authentication and version is set up correctly.

Hope this helps.
Yaara

Thanks for the instructions on creating the documentation via the UI. However, I am wondering about the procedure to create documentation entries via the API without the UI

So I dug into the Angular UI code. It looks like I am wrong with the jwt token encoded part.

It is in fact just Base64ed.

...
$scope.docs.documentation = Utils.b64EncodeUnicode($scope.docs.tempDocumentation)
...

https://tyk.io/docs/tyk-dashboard-api/

Have you been able to attach documentation through API? And then see it in portal.

Yes,

function createDocumentation (userAuthorization, policyId, document) {
  return fetch(`${dashboardHost}/api/portal/documentation`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      authorization: userAuthorization
    },
    body: JSON.stringify({
      api_id: policyId,
      doc_type: 'swagger',
      documentation: new Buffer(JSON.stringify(document)).toString('base64'),
      tempDocumentation: document

    })
  })
    .then(res => res.json())
}

Then you need to attach the document ID to the list of policies in the API Portal.

      .then((data) => createDocumentation(userAuthorization, policyId, data))
      .tap((data) => {
        let documentId = _.get(data, 'Message')
        policies.push({
          documentation: documentId,
          long_description: `This is the long description to the API: ${apiName}`,
          name: apiName,
          policy_id: policyId,
          short_description: `This is the short description to the API: ${apiName}`,
          show: true,
          version: 'v2',
        })
      })

Thanks a lot!!! By documentID you mean the Message field in the response when you perform /api/portal/documentation?

Yep, basically the ID of the documentation record from mongo.

Sorry the code snip is in Node.js