VTEX Developer Portal

Connecting to VTEX Core Commerce APIs

Context

A VTEX IO app is a first-class citizen to connect with VTEX Core Commerce API's (https://developers.vtex.com/reference), and it's very easy to create integrations with our modules.

📘

The Client you need may already be implemented on @vtex/clients. Check it out on https://github.com/vtex/commerce-io-clients

Steps

  1. On your app, create a Client that represents the module you want to access. It will be a class that extends JanusClient.
  2. On the constructor, setup the VtexIdclientAutCookie header with the token you want to use to authorize the request. Use ctx.authToken to use the app's token. You may also use ctx.vtex.storeUserAuthToken or ctx.vtex.adminUserAuthToken to use the requester's token, for request incoming from the VTEX Admin or VTEX Storefront. You can also pass that on each specific call.
  3. On each method, make the HTTP call using this.http using the path of the service you want to access. (e.g: /api/billing/company)
  4. On the app's manifest.json, add the appropriate outbound-access policy to the URL you are requesting. (example here)
  5. That's it. Now, finish the Client's setup according to the documentation, and you may now use it on our code.

Keep In Mind 👀

GraphQL Apps

  • Some of our Core Commerce Modules already have a GraphQL app that abstracts their endpoints, so it's important to check if the data you want to access is already exported via one of our GraphQL apps. You can check that on the GraphQL IDE app on your admin's (vtex install vtex.admin-graphql-ide if you can't see it)

Authentication

  • IO Apps don't need appKey/appToken to make requests to VTEX APIs, thus it's not necessary to ask the merchant to create this pair. Every app will have it's own rotating token that can be used on the app's code.
  • In some cases, it's not ideal to use the app's token (e.g: the authorization is important and depends on the calling user), and you can use the user's token instead, using ctx.vtex.storeUserAuthToken or ctx.vtex.adminUserAuthToken.

Some examples

Updated 8 months ago


Connecting to VTEX Core Commerce APIs


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.