Calling api from premap hook

I am wondering if an API call can also be done from a import flow step > preMap hook?
The API and flow step are both in the same Sandbox and both connecting to the same NS connection. When doing a call to the API function I get this error back:

{"statusCode":400,"headers":{},"body":"{\"code\":\"invalid_reference\",\"message\":\"The Export which you are trying to create is not of type sandbox but it has Connection reference with _id: 60a*****removed******80fb which is of type sandbox.\"}"}

Tried to search in the docs but unfortunately did not find anything.

0

Comments

3 comments
Date Votes
  • The specific error message you posted indicates that you are trying to create an export that references a sandbox connection, but for some reason the export itself is being created in production.  You might be able to work around this by explicitly setting the "sandbox" boolean field to true on the export resource before posting it to the API.

    Taking a step back I don't recommend creating new resources in your hooks in your flows (i.e. dont create new exports and imports).  You should create the exports and imports that you need in advance, and then simply invoke them in your hooks; or you should use virtual exports and imports.  Invoking exports and imports in your hooks is a very powerful capability, and you can do really cool stuff, but please also be careful with this power.  I always recommend trying to use flow builder to do as much as possible, because then it is easier to visualize and maintain the stuff you build, and you get better err management, and concurrency controls are built in, etc...

    0
  • Hi Scott,

    Thanks again for taking the time to answer. 

    You might be able to work around this by explicitly setting the "sandbox" boolean field to true on the export resource before posting it to the API.

    Where can I find this option?

    I agree about the visualization part. Only sometimes if there are many steps it feels cleaner to do it in code hehe :)

    0
  • Regarding the "sandbox" boolean property, and the error you are seeing when you try to create an export in your hook, this is actually likely a bug.  i.e. The bug is that we are not auto setting the "sandbox" boolean field when your script runs in sandbox, and uses the API in the sandbox, etc...

    I am not sure if/when something like this will get fixed though, since again, it is really not a good practice to be creating new resources in hooks.

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post