A VTEX IO app is a first-class citizen to connect with VTEX Core Commerce API's (https://developers.vtex.com/docs/api-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
- On your app, create a Client that represents the module you want to access. It will be a class that extends JanusClient.
- On the constructor, setup the
VtexIdclientAutCookieheader with the token you want to use to authorize the request. Use
ctx.authTokento use the app's token. You may also use
ctx.vtex.adminUserAuthTokento use the requester's token, for request incoming from the VTEX Admin or VTEX Storefront. You can also pass that on each specific call.
- On each method, make the HTTP call using
this.httpusing the path of the service you want to access. (e.g:
- On the app's
manifest.json, add the appropriate
outbound-accesspolicy to the URL you are requesting. (example here)
- 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 👀
- 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-ideif you can't see it)
- 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