Include custom API relation to Customer Rest API
We're working on headless approach and create custom API to subscribe/unsubscribe to newsletter, API is working fine, now we want to include newsletter status to customer Rest API, for that we've added to relationship dependency $resourceRelationshipCollection->addRelationship( CustomersRestApiConfig::RESOURCE_CUSTOMERS, new NewslettersRestApiResourceRelationshipPlugin(),);
To Retrieve newsletter status we're using newsletter's checkSubscription
function, when we include newsletter in customer API I am getting data in my function
Array( [type] => newsletters [id] => [attributes] => Array ( [isSubscribe] => )
[links] => Array ( [self] => customers/DE--14 )
[relationships] => Array ( [newsletters] => Array ( [data] => Array ( [0] => Array ( [type] => newsletters [id] => )
)
)
)
)
But it is not included in final output of customer API, let me know what we're doing wrong here
Answers
-
Hi, @mk00559179 !
Since I don't see the exact request you make, I post here the one I'm expecting you to make, please confirm it: GET https://glue.spryker.local/customers/<REFERENCE>?include=newsletters
assuming that
newsletters
is the name of the resource in your replationship plugin (returned by getRelationshipResourceType)Documentation:
1 -
I've resolved this issue.
I am not passing $restResponse variable properly
Thanks for your input.
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 75 Spryker News
- 919 Developer Corner
- 779 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 34 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 25 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 69 Spryker Safari Questions
- 50 Random